Reputation: 11
Can I use a page action to directly open a new page? I have a link in my popup.html, but it would be better to have the page open when they click the icon so that they would only need one click instead of two.
<!doctype html>
<html>
<head>
<title>Popup</title>
<link href="popup.css" rel="stylesheet" type="text/css">
</head>
<body>
<a href="http://www.domain.com/details.html" target="_blank">click here</a>
</body>
</html>
Upvotes: 1
Views: 427
Reputation: 21842
I don't think there is any elegant way to handle both the situations on page action click:
If you always want to open a new tab with some URL whenever page action is clicked, just remove the popup. And use the code just like @Flo has mentioned.
chrome.pageAction.onClicked.addListener(function(tab) {
chrome.tabs.create({url: "http://www.example.com", "active":true});
});
PS: To remove the popup, there are two options:
chrome.pageAction.setPopup('')
Upvotes: 1
Reputation: 983
Yes, a way to achieve this would be as follows:
chrome.pageAction.onClicked.addListener(function(tab){
chrome.tabs.create({url: "http://www.domain.com/details.html", "active":true});
});
See Chrome Page Action | onClicked
Note that you will need to declare the tabs permission in your manifest file:
"permissions": ["tabs",...],
Upvotes: 2