How to modify current url location in chrome via extensions

后端 未结 3 1706
春和景丽
春和景丽 2020-12-04 11:43

I want to create an extension that redirects the user to another website if he clicks on the extension button. So far I have only seen extensions which create a new tab for

3条回答
  •  囚心锁ツ
    2020-12-04 12:05

    The chrome.tabs.update method will automatically run on the current active tab if no tab id is passed.

    This has the added advantage of not requiring the tabs permission. Extensions with this permission warn the user that they can read the browsing history, so you should avoid asking for it if you don't need to.

    Changing the current tab's URL is as simple as writing this:

    chrome.tabs.update(undefined, {url: 'http://example.com'});
    

    Or as mentionned by farwayer in the comments, you don't need to put two arguments at all.

    chrome.tabs.update({url: 'http://example.com'});
    

提交回复
热议问题