Skip to content Skip to sidebar Skip to footer

Javascript Code Not Displaying Wanted Output

I've written some code to display my favorites in IE8 but for an unknown reason I have no output on the screen despite the fact that my page is accepted by IE and that the test tex

Solution 1:

The following works for me:

var fso, favs = [];
function GetFavourites(Folder) {
    varFavFolder= fso.GetFolder(Folder);
    //Gets Favourite Names & URL's for given folder.varfiles=newEnumerator(FavFolder.Files);
    for (; !files.atEnd(); files.moveNext()) {
        varfil= files.item();
        if (fil.Type == "Internet Shortcut") {
            vartextReader= fso.OpenTextFile(fil.Path, 1, false, -2);
            varfavtext= textReader.ReadAll();
            varstart= favtext.indexOf("URL", 16);
            varstop= 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 any subfolder existsvarsubfolders=newEnumerator(FavFolder.SubFolders);
    for (; !subfolders.atEnd(); subfolders.moveNext()) {
        varfolder= subfolders.item();
        GetFavourites(folder.Path);
    }
}
function Import() {
    try {
        fso = newActiveXObject("Scripting.FileSystemObject");
        if (fso !== null) {
            //Create windows script shell object to access Favorites folder in user system.varobject=newActiveXObject("WScript.Shell");
            varfavfolderName= object.SpecialFolders("Favorites");
            if (favString === "") {
                GetFavourites(favfolderName);
            }
        }
    }
    catch (err) {
        alert("Security settings to be modified in your browser ");
    }
}

Note that all I changed was the output from an element to an array named favs. I also removed the i variable, because it wasn't used. After running the script, I checked the array in the developer tools console and it contained all my favourites.

Solution 2:

If you're getting no output at all, then either fso is null in the Import method or files.AtEnd() always evaluates to false. Since you're focusing on IE here, you might consider placing alert methods in various places with values to debug (such as alert(fso);) throughout your expected code path.

Post a Comment for "Javascript Code Not Displaying Wanted Output"