2

我想修改chrome扩展的popup.html。我加载了一个 iFrame,其中包含一个外部 URL。加载 iFrame 后,我想修改 popup.html 中的 div 标签

popup.html

<head>
    <script type = "text/javascript" src = "popup.js"></script>
</head>

<body>
    <form name = "getPage" action = "http://website.com/" method = "post" target = "post_stuff">
        <input type = "hidden" name = "hdnrequesttype" value = "1" />
        <input type = "hidden" name = "txtmemberid" id = "txtmemberid" value = "11012333" />
        <input type = "hidden" name = "txtmemberpwd" id = "txtmemberpwd" value = "" />
        <input type = "hidden" name = "sites" value = "0" />
        <input type = "hidden" name = "firsttime" value = "Y" />
    </form>
    <iframe name = "post_stuff" height = "600" width = "600" onload = "frame_loaded()">
    </iframe>
    <div id = "putText">
    </div>
</body>

popup.js

window.onload = function() {
    document.forms["getPage"].submit();
}

function frame_loaded() {
    document.getElementById("putText").innerHTML = "LOADED";
    console.log("LOADED");
}

这没有用。我尝试使用内容脚本,但这也不起作用。我的内容脚本 modify.js 的内容:-

修改.js

document.getElementById("putText").innerHTML = "LOADED";

这是我清单的相关部分:-

"content_scripts" : [ {
                            "matches": ["<all_urls>"],
                            "js": ["modify.js"]
                       }
                    ]

我希望有人可以帮助我。

4

1 回答 1

3

我猜你正在使用manifest_version: 2. 如果是这样,您将需要使用addEventListener而不是您的内联onload处理程序:

window.onload = function() {
    //attach a load listener to the iframe
    document.querySelector("iframe").addEventListener("load", frame_loaded);
    document.forms["getPage"].submit();
}
于 2012-08-23T18:12:49.507 回答