如何设置iframe's在firefox扩展对话框中的src

how to set iframe's src in firefox extension dialog

本文关键字:firefox 扩展 对话框 src 何设置 设置 iframe      更新时间:2023-09-26

我想在对话框中动态设置iframe的src。但是以下代码不起作用。

    <?xml version="1.0"?>
    <?xml-stylesheet href="chrome://global/skin/"?>
    <dialog id="clockDialog" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      onload="init();">
      <script type="application/javascript" src="chrome://test/content/clock.js"/>
      <iframe id="content-body" flex = "1" onload="ini()"/>
    </dialog>
    function init() {
      document.getElementById("content-body").src = "http://www.google.com";
    }

这样做正确吗?非常感谢。

还有一个类似的问题如何动态设置";src";用于浏览器或iframe元素(Firefox扩展)这也没有得到回答。

这应该有效:

document.getElementById("content-body").setAttribute("src","http://www.google.com");

而且你的来电中有一个打字错误。它应该是init();

编辑:

别忘了设置type属性。iframe-XUL|MDN

编辑2:上面的错别字不是真的。您已加载对话框上的正确调用。

我刚刚用上面的代码测试了它,它很有效。