internet explorer - Javascript code not displaying wanted output -
i've written code display favorites in ie8 unknown reason have no output on screen despite fact page accepted ie , test text 'this test' displayed.
my code :
<html> <head> <meta http-equiv="content-type" content="text/html; charset=iso 8859-1" /> <script type="text/javascript"> var = 0; var favstring = ""; var fso; function getfavourites(folder) { var favfolder = fso.getfolder(folder); //gets favourite names & url's given folder. var files = new enumerator(favfolder.files); (; !files.atend(); files.movenext()) { var fil = files.item(); if (fil.type == "internet shortcut") { var textreader = fso.opentextfile(fil.path, 1, false, -2); var favtext = textreader.readall(); var start = favtext.indexof("url", 16); var stop = favtext.indexof("\n", start); favstring += fil.name.replace(/.url/, ""); favstring += ":url:"; //to separate favourite name & favorite url favstring += favtext.substring(start + 4, stop - 1); favorites.innerhtml += favstring; // not working ! favorites.innerhtml += 'test'; // not working ! favstring += ":next:"; //to separate favorites. i++; } } //checks subfolder exists var subfolders = new enumerator(favfolder.subfolders); (; !subfolders.atend(); subfolders.movenext()) { var folder = subfolders.item(); getfavourites(folder.path); } } function import() { try { fso = new activexobject("scripting.filesystemobject"); if (fso !== null) { //create windows script shell object access favorites folder in user system. var object = new activexobject("wscript.shell"); var favfoldername = object.specialfolders("favorites"); if (favstring === "") { getfavourites(favfoldername); } } } catch (err) { alert("security settings modified in browser "); } } </script> </head> <body onload="import()"> <p>this test</p> <!-- working ! --> <div id="favorites"> </div> </body> </html>
the following works me:
var fso, favs = []; function getfavourites(folder) { var favfolder = fso.getfolder(folder); //gets favourite names & url's given folder. var files = new enumerator(favfolder.files); (; !files.atend(); files.movenext()) { var fil = files.item(); if (fil.type == "internet shortcut") { var textreader = fso.opentextfile(fil.path, 1, false, -2); var favtext = textreader.readall(); var start = favtext.indexof("url", 16); var stop = favtext.indexof("\n", start); favstring = fil.name.replace(/.url/, ""); favstring += ":url:"; //to separate favourite name & favorite url favstring += favtext.substring(start + 4, stop - 1); favs.push(favstring); } } //checks subfolder exists var subfolders = new enumerator(favfolder.subfolders); (; !subfolders.atend(); subfolders.movenext()) { var folder = subfolders.item(); getfavourites(folder.path); } } function import() { try { fso = new activexobject("scripting.filesystemobject"); if (fso !== null) { //create windows script shell object access favorites folder in user system. var object = new activexobject("wscript.shell"); var favfoldername = object.specialfolders("favorites"); if (favstring === "") { getfavourites(favfoldername); } } } catch (err) { alert("security settings modified in browser "); } }
note changed output element array named favs
. removed i
variable, because wasn't used. after running script, checked array in developer tools console , contained favourites.
Comments
Post a Comment