How To Redirect Current Tab's Url In Chrome Extension?
Solution 1:
See chrome.tabs.update
, you could update the url of current tab via the following code
chrome.tabs.update({url: "http://www.baidu.com"});
Considering you get the keyword from content script, and want to redirect the url after user clicks some button in popup page, you may need Message Passing or chrome.storage to share the keywords between content script and popup page.
Solution 2:
There are 2 possible approaches:
A. Let the popup handle redirection. B. Let the content script handle redirection.
In both cases, you need to solve 2 problems:
Communicate information between the two. In approach A, you need to get the keywords from the content script. In approach B, you need to tell the content script which engine to switch to.
Both are solved using Messaging. I recommend messaging from the popup to the content script using
chrome.tabs.sendMessage
(and responding in approach A), because in the other direction content script doesn't know when to send the message (popup may be closed).Actually trigger the change. In approach A,
chrome.tabs.update
does the trick. In approach B, content script can changewindow.location
to navigate away.
Post a Comment for "How To Redirect Current Tab's Url In Chrome Extension?"