相关疑难解决方法(0)

如何为特定页面显示page_action?

我正在玩一些chrome扩展,我发现了这个例子:http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/

一切正常,但我想创建自己的扩展,我想在特定网站上看到page_action图标,而不是在网址中看到'g'的图标.所以我试着简单地从这个改变脚本:

// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Called when the url of a tab changes.
function checkForValidUrl(tabId, changeInfo, tab) {
// If the letter 'g' is found in the tab's URL...
if (tab.url.indexOf('g') > -1) {
// ... show the page action.
chrome.pageAction.show(tabId);
}
};

// Listen for any changes …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome-extension

16
推荐指数
1
解决办法
1万
查看次数

Chrome扩展程序tab.url未定义

我在popup.html中使用带有按钮的chrome扩展程序,打开一个新标签页.新选项卡的目标URL将当前(原始)选项卡的URL保存为参数.

例如:当从中触发时http://stackoverflow.com/,新选项卡应该具有类似的URLhttp://www.mydestination.com/index.php?url=http://stackoverflow.com/

这是我的js:

document.addEventListener('DOMContentLoaded', function (tab) { 

    document.getElementById('button').addEventListener("click", function(tab) {
        chrome.tabs.create({url: 'http://www.mydestination.com/index.php?url=' + tab.url});
    }); 

})
Run Code Online (Sandbox Code Playgroud)

新选项卡完全打开,但URL为http://www.mydestination.com/index.php?url=undefined(url = undefined).

我认为manifest.json拥有正确的权限:

{      
"manifest_version": 2,
"name": "My project",
"version" : "1.7",
"browser_action": {
  "default_icon" : "img/icon.png",
  "default_title" : "My project",
  "default_popup": "html/main.html" 
},
"permissions": [
  "tabs"
],
"icons": {
  "16": "img/icon.png"
}
}
Run Code Online (Sandbox Code Playgroud)

有关如何正确运输网址的任何线索?

google-chrome-extension

5
推荐指数
1
解决办法
3596
查看次数