Javascript XUL:如何允许从浏览器脚本访问顶部窗口(当src是localhost时)

Javascript XUL:如何允许从浏览器脚本访问顶部窗口(当src是localhost时),javascript,xul,Javascript,Xul,XUL: test.html: <?xml-stylesheet href="chrome://global/skin" type="text/css"?> <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <browser type="chrome" disablesecurity="true" src="http://localhost:60000

XUL:

test.html:

<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    <browser type="chrome" disablesecurity="true" src="http://localhost:60000/test.html" flex="1" disablehistory="true" />
</window>
jsconsole中出错:访问属性“文档”的权限被拒绝


如果我改变http://localhost:60000/test.html 到chrome://test.html 然后一切正常,但就我而言,我可以通过web服务器访问。

出于安全原因,您不能按自己的方式做自己想做的事情

从非chrome://地址或其他Firefox扩展特定协议(如resource://)加载的页面在所有非特权普通网页的安全上下文中运行。这明显阻止的事情之一是访问当前页面之外的Firefox区域。因此,访问当前浏览器窗口的父窗口的尝试应该总是失败的

使用chrome://test.html 浏览器URL栏中的地址明确指示Firefox在扩展的更高安全性上下文中加载页面,该扩展可以访问大部分Firefox

如果需要从非特权文档访问chrome://资源,可以使用自定义DOM事件实现消息传递。但是,在特权端,您必须在执行此操作的Firefox配置文件中安装Firefox扩展。换句话说,用户必须通过安装扩展的过程,或者至少从chrome://地址访问某些内容,来授予特权级别的访问权限。这些地址只能从用户本地文件存储上数量非常有限的文件夹中获得

如果您想了解更多信息,在MDN上有一个页面

<script>
    window.parent.document.title = "abc";
</script>