0
我已經寫了一些代碼來顯示我的書籤在IE8上。代碼工作正常,除了我應該有的收藏夾(「收藏」)作爲輸出存在,但是是空的(當我把「favs」放在開發人員工具控制檯中時,我得到{...})。Javascript在IE上返回空陣列(這不應該)IE
var fso, favs = [];
var favString="";
function GetFavourites(Folder) {
var FavFolder = fso.GetFolder(Folder);
//Gets Favourite Names & URL's for given folder.
var files = new Enumerator(FavFolder.Files);
for (; !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 any subfolder exists
var subfolders = new Enumerator(FavFolder.SubFolders);
for (; !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 to 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 to be modified in your browser ");
}
}
你有沒有試過在控制檯輸入'favs [0]'?據我所知,IE8的調試工具不能顯示orbject數組的內容。 – 2011-05-12 09:32:31
@freaktm是的我試過了;我也嘗試過用For結構來瀏覽數組。但我很確定數組是空的,因爲我得到0與favs.length – Bruno 2011-05-12 09:34:31
你檢查了你的收藏夾文件夾(C:\ Users \ Bruno \ Favorites)是不是空的? =) – 2011-05-12 09:43:03