Opening a new tab on Google Chrome Extension
You should read the chrome.tabs.create
documentation again. You are passing it invald parameters. You are also using location
which is from the background.html
document not the webpage document the code is expecting instead of the tab
parameter passed to the chrome.browserAction.onClicked
listener.
<html>
<head>
<script>
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
var action_url = "http://www.reddit.com/submit?url=" + encodeURIComponent(tab.href) + '&title=' + encodeURIComponent(tab.title);
chrome.tabs.create({ url: action_url });
});
</script>
</head>
</html>
You can try this
<html>
...
<body>
<script>
function createTab() {
chrome.tabs.create({url: "http://www.stackoverflow.com"});
}
</script>
<a href="#" onclick="createTab();">Create a new tab</a>
</body>
</html>