我希望使用Javascript将页面重定向到另一个页面。我已经尝试过使用document.location.href,但它不适用于本地页面(存储在我的硬盘中)。 有人知道会做诡计的事吗?使用Firefox扩展重定向到语言环境页面
感谢,
布鲁诺
我希望使用Javascript将页面重定向到另一个页面。我已经尝试过使用document.location.href,但它不适用于本地页面(存储在我的硬盘中)。 有人知道会做诡计的事吗?使用Firefox扩展重定向到语言环境页面
感谢,
布鲁诺
上扩展的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
不是吗?我尝试了以下工作得很好:
<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
改为尝试'window.location'。 'document.location'是只读的。 – 2011-04-12 12:20:13
我试过了,它不起作用。 – Bruno 2011-04-12 12:21:58
看到这个: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