Javascript 在iframe chrome扩展上运行JS
我正在创建一个简单的chrome扩展,以便在弹出窗口中加载一个我无权访问代码的页面 然而,该网站没有API来获取我想要的内容。因此,我在iFrame中加载了页面,并尝试使用JS删除iFrame中不需要的内容 Manifest.JSON:Javascript 在iframe chrome扩展上运行JS,javascript,json,google-chrome-extension,Javascript,Json,Google Chrome Extension,我正在创建一个简单的chrome扩展,以便在弹出窗口中加载一个我无权访问代码的页面 然而,该网站没有API来获取我想要的内容。因此,我在iFrame中加载了页面,并尝试使用JS删除iFrame中不需要的内容 Manifest.JSON: { "manifest_version": 2, "name": "Website Ext", "description": "My Description", "version": "1.0", "browser_action": {
{
"manifest_version": 2,
"name": "Website Ext",
"description": "My Description",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/"
]
}
Popup.html
<!doctype html>
<html>
<head>
<title>My extension</title>
<style>
body {
font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif;
font-size: 100%;
}
#status {
/* avoid an excessively wide status text */
white-space: pre;
text-overflow: ellipsis;
overflow: hidden;
width: 600px;
height; 800px
}
</style>
<script src="popup.js"></script>
</head>
<body>
<div id="status">
<iframe src="http://domain.com" width="590px" height="795px">
</div>
</body>
</html>
然而,JS似乎被忽略了,任何关于如何使其工作的建议都将被感激
我已经在chrome开发者工具中测试了JS,它也剥离了我想要的东西。您正在尝试跨域操作。我怀疑这是允许的。使用内容脚本修改内容,allframes为true。示例:您尝试跨域操作的内容可能重复。我怀疑这是允许的。使用内容脚本修改内容,allframes为true。示例:的可能重复
Element.prototype.remove = function() {
this.parentElement.removeChild(this);
}
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
for(var i = this.length - 1; i >= 0; i--) {
if(this[i] && this[i].parentElement) {
this[i].parentElement.removeChild(this[i]);
}
}
}
document.getElementById("headerbody").remove();
document.getElementById("footerbody").remove();
document.getElementById("breadcrumb").remove();
document.getElementById("pagetitle").remove();
document.getElementById("actionbar").remove();