chrome.extensions =>如何在popup.html中记录document.write

时间:2017-12-04 13:01:23

标签: javascript dom google-chrome-extension

我想使用函数document.write来在chrome.extension的popup.html 中写一些东西,但我无法使它工作。谷歌已经抓了几个小时但仍然卡住了。

popup.html

<!DOCTYPE html>
<html>
<head><meta charset="utf-8">
</head>
<body>
<div id ="master">
</div>
</body></html>

的manifest.json

{
"manifest_version": 2,
"name": "Example",
"description": "Description",
"version": "1.0",
"browser_action": 
{
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "myweb.com"
},
"background": 
{
"scripts": [ "background.js" ],
"persistent": true
},
"permissions": [
"activeTab",
"alarms",
"storage",
"notifications",
"tabs"
]
}

这里是导致background.js中出现问题的代码:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
document.master.write( '<iframe src="http://www.xxxx.com/someaction" ' +
    'style="padding:0px; overflow:hidden;" '+
    'width="400px" height="350px"></iframe>' );
...///...

触发错误:

  

tabs.onUpdated的事件处理程序出错:TypeError:无法读取   属性'写'未定义

感谢您的帮助!

0 个答案:

没有答案