Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Extension: onclick extension icon, open popup.html in new tab

Tags:

I have created a chrome extension and managed to open the popup.html file using window.open. however I want to open it in a new tab, I've tried lots of different ways including:

<script type="text/javascript" language="JavaScript">   chrome.tabs.create('url': 'popup.html'); 

Am I just placing the code in the wrong place or is it the wrong code altogether?

like image 894
David Avatar asked Mar 09 '10 20:03

David


People also ask

How do I get Chrome to open popups with new tabs?

If you don't want to use those extensions, then the most simple solution is to Ctrl + Click the link you think it's a pop-up: it will be open as a new tab.

How can I have Chrome automatically open a new tab when I click on a link?

For this, you have to hold the CTRL button and then click on the left mouse button while pointing the cursor to the web address. If you click on a link in this manner, the website won't open in your current tab; instead, you'll see a new tab with your preferred web page.


2 Answers

why would you want to open the popup.html in a new tab? You should create a different page for that. Anyways, if you want to open up the popup.html, in a new tab, you would need to pass in the extension url.

http://code.google.com/chrome/extensions/extension.html#method-getURL

chrome.tabs.create({'url': chrome.extension.getURL('popup.html')}, function(tab) {   // Tab opened. }); 
like image 99
Mohamed Mansour Avatar answered Sep 27 '22 22:09

Mohamed Mansour


Now you can use Event Pages to open popup.html in new tab when extension icon is clicked without creating a default_popup page.

manifest:

"background": {     "scripts": ["background.js"],     "persistent": false } 

js:

chrome.browserAction.onClicked.addListener(function(tab) {     chrome.tabs.create({'url': chrome.extension.getURL('popup.html'), 'selected': true}); }); 
like image 25
wander Avatar answered Sep 27 '22 22:09

wander