Reputation: 953
I'm trying to make a personal Chrome extension with tabs to my most visited websites. I have a large border to the side of my tabs that I want to use as a button, which will open every link in a new tab when pressed.
I currently have the button set as this:
<button class="left-button" onclick="topLeft()"></button>
I have some JavaScript setup like this:
function topLeft() {
window.open('https://www.youtube.com');
window.open('https://www.reddit.com');
window.open('https://www.facebook.com');
window.open('https://outlook.live.com');
};
The above works perfectly before uploading it as an extension to Chrome (as in it works fine when run locally). Once it's uploaded as an extension, the button can be pressed, but nothing happens.
I have tried replacing my
window.open('url');
With
chrome.tabs.create({url: "myurls" });
But the results were unsuccessful.
My manifest.json file looks like this:
{
"manifest_version": 2,
"name": "my extension",
"description": "A Homepage extension.",
"version": "1.0",
"permissions": ["tabs"],
"chrome_url_overrides" : {
"newtab" : "index.html"
}
}
Upvotes: 1
Views: 68
Reputation: 10897
For chrome extension, by default Inline JavaScript will not be executed, that means onLeft
method won't be triggered for the following line.
<button class="left-button" onclick="topLeft()"></button>
Please try the following way to bind click handler:
<button id="LEFT_BUTTON_ID" class="left-button" onclick="topLeft()"></button>
document.getElementById('LEFT_BUTTON_ID').addEventListener('click', topLeft);
Upvotes: 2