I want to load a new page in current tab by clicking on link displayed in the Chrome extension. How can I do that?
I tried assigning the onClick attribute but it does not work for security reasons.
I want to load a new page in current tab by clicking on link displayed in the Chrome extension. How can I do that?
I tried assigning the onClick attribute but it does not work for security reasons.
You need to find the current tab, and then update it. chrome.tabs
is the API to use.
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.update(tabs[0].id, {url: "http://example.com/"});
});
Note that this does not need a "tabs"
permission.
And in general, regarding the onClick
problems, see this documentation and this question.
You can use programmatic injection. Just add a listener for click event which executes the script in the tab. Then this script will change the url.