简体   繁体   中英

Chrome extension jump to URL

I would like to make a google chrome extension. I want to add a function, so when i click on it's icon, it will open a new tab with a specific URL. How can I do that? Sorry for bad english, I'm just learning that language;)

If you want to open a link in a new tab when you click on a page action icon you can use the onClicked method of the pageAction: http://code.google.com/chrome/extensions/pageAction.html#event-onClicked

So, in the background page or script add the following lines:

    chrome.pageAction.onClicked.addListener(function(tab) {
        windowObjectReference = window.open("http://google.com/", "DescriptiveWindowName", "resizable=yes,scrollbars=yes,status=yes");  
});

Note, that onClicked event is NOT fired when page action has a popup page that is displayed when page action is clicked. So in order to use onCLicked event you should NOT have a page action popup page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM