简体   繁体   中英

Redirection to a locale page with a Firefox extension

I'd like to have a page redirecting to another using Javascript. I've tried with document.location.href but it doesn't work with local pages (stored in my hard drive). Does someone know something that would do the trick ?

thanks,

Bruno

Doesn't it? I've tried the following and it works fine:

<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>

Tested in IE8 and Chrome

Posting this on the xul file of the extension :

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

);

the complete extension : http://uploadingit.com/file/xef7llflgmjgfzin/my_firefox_extension.xpi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM