【发布时间】:2012-01-13 16:25:18
【问题描述】:
所以我想在按 OK 时获取选定选项卡的 html。但是有些东西不起作用。我错过了什么?
manifest.json
{
"name": "extension",
"version": "1.0",
"description": "discription",
"content_scripts": [
{
"matches": ["http://www.google.com/*"],
"js": ["contentscript.js"]
}
],
"browser_action": {
"default_icon": "icon.png",
"popup": "popup.html"
},
"permissions": [
"http://ajax.googleapis.com/",
"tabs"
]
}
popup.html
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script>
</head>
<body>
<script>
function getHTML()
{
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {method: "getHTML"}, function(response) {
if(respond.method="getHTML"){
alert(response.html);
}
});
});
}
</script>
<input type="submit" value="OK" onclick ="getHTML()" />
</body>
contentscript.js
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if(request.method == "getHTML"){
sendResponse({html: document.all[0].outerHTML});
}
}
);
【问题讨论】:
-
很难看到问题的本质。 1)“不起作用”是什么意思?你看到了什么。 2)您是否尝试过调试您的扩展程序?你有没有想出一个更集中的故障点?
-
甚至没有警报消息,当我点击确定时没有任何反应
-
你试过用chrome debugger调试它吗?
标签: html google-chrome tabs google-chrome-extension