2011-04-12 75 views
0

我希望使用Javascript將頁面重定向到另一個頁面。我已經嘗試過使用document.location.href,但它不適用於本地頁面(存儲在我的硬盤中)。 有人知道會做詭計的事嗎?使用Firefox擴展重定向到語言環境頁面

感謝,

布魯諾

+0

改爲嘗試'window.location'。 'document.location'是隻讀的。 – 2011-04-12 12:20:13

+0

我試過了,它不起作用。 – Bruno 2011-04-12 12:21:58

+3

看到這個:http://stackoverflow.com/questions/1254572/cross-browser-link-to-file-on-local-system和這一個爲IE瀏覽器:http://superuser.com/questions/266908/why -doesnt-a-link-to-a-local-word-document-work-in-internet-explorer底線 - 由於安全原因,這是不可能的。 – 2011-04-12 12:22:36

回答

0

上擴展的XUL文件發佈此:

function Read(file) 
{ 
var ioService=Components.classes["@mozilla.org/network/io-service;1"] 
    .getService(Components.interfaces.nsIIOService); 
var scriptableStream=Components 
    .classes["@mozilla.org/scriptableinputstream;1"] 
    .getService(Components.interfaces.nsIScriptableInputStream); 

var channel=ioService.newChannel(file,null,null); 
var input=channel.open(); 
scriptableStream.init(input); 
var str=scriptableStream.read(input.available()); 
scriptableStream.close(); 
input.close(); 
return str; 
} 

gBrowser.addEventListener("DOMContentLoaded", function(e) { 
    var documentElement = e.originalTarget.defaultView.document; 
    var div = documentElement.createElement("div"); 
    div.innerHTML = Read("chrome://firefox_extension/content/locale.html"); 
    documentElement.body.appendChild(div); 
}, 

false 

); 

完整的分機號:http://uploadingit.com/file/xef7llflgmjgfzin/my_firefox_extension.xpi

0

不是嗎?我嘗試了以下工作得很好:

<html> 
    <head> 
     <meta http-equiv="content-type" content="text/html;charset=utf-8"> 
    </head> 
    <body> 
     <input type="text" value="" id="test"/> 
    </body> 

    <script type="text/javascript"> 
     document.location.href = "file:///C:/dev/PICCS/vb/binaries/"; 
    </script> 
</html> 

測試在IE8和Chrome

+0

你在FireFox中試過這個嗎? – 2011-04-12 12:23:26

+0

我試過了你的訣竅:文件確實打開,但裏面沒有任何東西 – Bruno 2011-04-12 12:27:51

+0

沒有谷歌瀏覽器,我的文件在wamp的www文件夾內。 – Bruno 2011-04-12 12:28:35