我想修改chrome扩展的popup.html。我在其中加载了一个包含外部URL的iFrame。加载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: -
modify.js
document.getElementById("putText").innerHTML = "LOADED";
以下是我的清单的相关部分: -
"content_scripts" : [ {
"matches": ["<all_urls>"],
"js": ["modify.js"]
}
]
我希望有人能帮助我。
答案 0 :(得分:2)
我猜你正在使用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();
}