This is my background.html file, It works fine when opening in current tab but I want it to open in new tab, what am I doing wrong?
<html>
<head>
<script>
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
var action_url = "javascript:location.href='http://www.reddit.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)";
chrome.tabs.create(tab.id, {url: action_url}, function(tab));
});
</script>
</head>
</html>
You should read the
chrome.tabs.createdocumentation again. You are passing it invald parameters. You are also usinglocationwhich is from thebackground.htmldocument not the webpage document the code is expecting instead of thetabparameter passed to thechrome.browserAction.onClickedlistener.