问题
I am a new one for the extension. I want to open a chrome extension page programmatically. Eg:
chrome-extension://njlkegdphefeellhaongiopcfgcinikh/options.html
When I click the web page button or link I want to open the particular extension tab.
I tried many ways. Directly call using javascript and so many ways. But I couldn't find the proper solution. Anybody have any idea.
(My target is using JavaScript to open the extension tab)
回答1:
Here is one of the solutions:
- Make sure your content script runs on the page on which you are clicking on the button.
When you click on button on web page, add event listener from content script and in the event listerner pass a messgae to background.
chrome.runtime.sendMessage({message: 'buttonClicked'}, function() { /* callback */ });
In your background script, listen to the message from content script.
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { if (request.message == 'buttonClicked') { // Create a new tab with options page } });
To create a new tab with options.html page, you can do this
chrome.tabs.create({ active: true, url: 'options.html' }, null);
来源:https://stackoverflow.com/questions/22761819/how-to-open-chrome-extension-page-programmatically