【发布时间】:2013-07-22 11:20:27
【问题描述】:
谁能告诉我如何在后台打开网址以及如何从中获取数据。我要打开的 URL 位于我也从中获取数据的页面中。我使用 XPath 来获取数据。 这是我的代码:
Popup.js
chrome.tabs.query({
active: true,
currentWindow: true }, function(tabs){
if(tabs[0].url.indexOf("extranet.louvre-hotels.fr")!=-1)
{
chrome.tabs.sendRequest(tabs[0].id, {
action: "getDOM"
}, function(response)
{
chrome.tabs.getSelected(null, function(tab) {
// get response
});
});
}
});
Manifest.json
{
"manifest_version": 2,
"name": "SymaExtract",
"description": "SymaExtract",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"webNavigation",
"tabs",
"background",
"http://localhost/extract.php",
"http://*/*"
],
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["dom.js"]
}
] }
Background.js
chrome.tabs.create({url: 'url_that_i_want_to_open'});
【问题讨论】:
-
Chrome desktop notification for dynamic site update when chrome runs in background 的可能重复项,其中提问者想要获取页面内容并在后台页面中检查它们。再说一次,可能不是完全重复,因为我不是 100% 清楚你想做什么(但该链接可能仍然有用)。
-
问题含糊不清。 “在后台”是什么意思?这可能就是你要找的东西:Chrome extension: loading a hidden page (without iframe)
标签: google-chrome google-chrome-extension