javascript - Implementing FileSaver.js saveAs() function into HTML script -


right attempting save information html page creating text document, using javascript , filesaver.js package. not versed in html , new javascript, odds making egregious mistake. @ moment, have eligrey's filesaver.js file in same directory html file working from, should able call "filesaver.js" in html.

right working this:

//some irrelevant text    <script src="filesaver.js">    function download(){            //alert("hello world");      //this alert line test function call      //the alert appears when <script> tag      // has no src field labeled. observation.            var blob = new blob(["hello world"],{type:"text/plain;charset=utf-8"});      saveas(blob,"helloworld.txt");     }  </script>    //some more irrelevant text    <input type="button" value="download" onclick="download();"/>  /*from button want gather information input text fields on page.   know how that, problem creating and, subsequently,   downloading text file trying create. simplicity's sake, text   capturing in example hardcoded "hello world"*/    //last of irrelevant text  //oh, , don't try run snippet :p

i have eligrey's blob.js file available in immediate working directory well, in case.

as of now, button nothing. sure calling function correctly considering receive javascript alert text, @ least when script tag had no src. if add src, absolutely nothing happens. browser testing latest google chrome stable build (43.0 think) on windows xp. please inform me of missing and/or doing wrong. in advance

you cannot have script tag src attribute , content inside tag. split 2 separate script tags. see what if script tag has both "src" , inline script?

note <script> cannot self-closing tag

<script src="filesaver.js"></script> <script>   function download(){      //alert("hello world");     //this alert line test function call     //the alert appears when <script> tag     // has no src field labeled. observation.      var blob = new blob(["hello world"],{type:"text/plain;charset=utf-8"});     saveas(blob,"helloworld.txt");    } </script> 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -