1
我用document.body.outerHTML
從標籤中取得的HTML,但我不能這樣做如何從當前選項卡獲得HTML彈出
manifest.json的:
{
"name": "SEO Analytic",
"description": "Adds a print button to the browser.",
"version": "1.2",
"manifest_version": 2,
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
],
"permissions": ["tabs", "http://*/*", "https://*/*"],
"browser_action": {
"default_title": "SEO Analytic",
"default_popup": "popup.html"
}
}
popup.js :
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {method: "getText"}, function(response) {
if (response.method == "getText") {
alltext = response.data;
alert(alltext);
}
});
});
content.js:
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if (request.method == "getText") {
sendResponse({
data: document.body.outerHTML,
method: "getText" // same as innerText
});
}
});
你試過我提出的解決方案嗎?如果你爲你工作? – gkalpak