【问题标题】:I can't access to an variables my extension Firefox from iframe我无法从 iframe 访问我的扩展 Firefox 的变量
【发布时间】:2012-10-13 12:49:02
【问题描述】:

随着新版本 Firefox 16 的发布,我的扩展程序会产生错误:“Permission denied to access property 'myVarExt'”。

browser.xul

<?xml version="1.0"?>
<!DOCTYPE overlay SYSTEM "chrome://mynewext/locale/overlay.dtd">
<overlay id="mynewext-overlay"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:svg="http://www.w3.org/2000/svg"
         xmlns:html="http://www.w3.org/1999/xhtml">
<script type="application/x-javascript;version=1.7" src="base.js"/>
<hbox id="browser">
    <splitter insertafter="sidebar-splitter"
              state="open"
              resizebefore="closest"
              resizeafter="closest"
              id="mynewext-splitter"
              hidden="true"/>
    <vbox id="mynewext-sidebar"
          insertafter="sidebar-splitter"
          width="308"
          minwidth="308"
          maxwidth="308"
          collapsed="true">
      <tabbox flex="1">
        <tabpanels id="mynewext-panels" flex="1">
          <iframe id="mynewext-dashboard" flex="1"/>
        </tabpanels>        
      </tabbox>
    </vbox>
  </hbox>
</overlay>

base.js文件中注册了填充iframe的变量和函数:

base.js

...
var myVarExt='Good!'; //Is the same variable that was accessed
...
var xulContentPanel=_('dashboard');
xulContentPanel.contentDocument.location.href = 'resource://mynewext/html/bodyfirefox.xhtml';
...

这样访问iframe的变量myVarExt

bodyfirefox.xhtml

<!DOCTYPE HTML><html xmlns="http://www.w3.org/1999/xhtml"><head>
    <title>myBar</title>
  </head>
<body><div id="testExtVar"></div></body>
<script type="text/javascript" >
var extVar=parent.myVarExt;
document.getElementById('testExtVar').innerHTML = extVar;
</script>
</html>

在旧版本的 Firefox 中,这种呼吁有效,而新版本没有。可能是什么问题?

【问题讨论】:

    标签: javascript firefox-addon


    【解决方案1】:

    问题解决了。

    1. iframe 不使用 type="content"
    2. resource://的内容转移到chrome://(chrome的优先级高于资源)。李>

    好吧,相应地重写了为 chrome

    支付给 resource 的方式

    【讨论】:

      猜你喜欢
      • 2014-02-07
      • 2012-01-10
      • 1970-01-01
      • 2012-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多