我如何为pageAction添加点击? [英] How can I add a click for pageAction?
问题描述
我的目标是在用户访问特定域中的页面时提供一个选项,以提供启动另一个页面的选项,使用部分被访问页面的域名作为变量。
下面的代码做我想要的,但它不提供作为选项的操作 - 它只是执行。
访问与该域名匹配的页面时,会在地址栏中添加一个图标。我希望只有当用户点击该图标时才调用新页面才能加载。如果这是不可能的,请提出一个替代方案。
谢谢!
function checkForValidUrl(tabId,changeInfo,tab){
if(tab.url.indexOf('。foo.com')> -1){
chrome。 pageAction.show(tabId);
var myName = tab.url.split(。)[0] .slice(7);
if(myName!=www){//忽略主站点
chrome.tabs.update(tab.id,{url:http:// foo .com / foo.html?t =+ myName});
}
}
};
chrome.tabs.onUpdated.addListener(checkForValidUrl);
您只需要使用 chrome.pageAction.onClicked
。例如:
function checkForValidUrl(tabId,changeInfo,tab){
if(tab.url.indexOf(' .foo.com')> -1)
chrome.pageAction.show(tabId);
};
chrome.tabs.onUpdated.addListener(checkForValidUrl);
chrome.pageAction.onClicked.addListener(function(tab){
var myName = tab.url.split(。)[0] .slice(7);
if(myName!=www)//忽略主站点
chrome.tabs.update(tab.id,{url:http://foo.com/foo.html?t=+ myName });
});
First extension—please be kind.
My objective is to offer an option when a user visits pages from a particular domain to offer an option to launch another page which uses part of the visited page's domain name as a variable.
This code below does what I want but it doesn't offer the action as an option—it just executes.
When a page that matches the domain is visited it adds an icon to the address bar. I want the new page called to loaded only when the user clicks on that icon. If that's not possible, please suggest an alternative.
Thanks!
function checkForValidUrl(tabId, changeInfo, tab) {
if (tab.url.indexOf('.foo.com') > -1) {
chrome.pageAction.show(tabId);
var myName = tab.url.split(".")[0].slice(7);
if (myName != "www"){ //ignore main site
chrome.tabs.update(tab.id, {url: "http://foo.com/foo.html?t=" + myName});
}
}
};
chrome.tabs.onUpdated.addListener(checkForValidUrl);
You just need to use chrome.pageAction.onClicked
. For example:
function checkForValidUrl(tabId, changeInfo, tab) {
if (tab.url.indexOf('.foo.com') > -1)
chrome.pageAction.show(tabId);
};
chrome.tabs.onUpdated.addListener(checkForValidUrl);
chrome.pageAction.onClicked.addListener(function(tab){
var myName = tab.url.split(".")[0].slice(7);
if (myName != "www") //ignore main site
chrome.tabs.update(tab.id, {url: "http://foo.com/foo.html?t=" + myName});
});
这篇关于我如何为pageAction添加点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!