Chrome extension; open a link from popup.html in a new tab

前端 未结 9 637
挽巷
挽巷 2020-12-04 16:23

I\'m doing a Chrome extension and I got helped in this post here.

My problem now is how to open a new tab of chrome that has as URL the link I clicked in the

9条回答
  •  一向
    一向 (楼主)
    2020-12-04 17:06

    If you don't want to use JQuery, insert this into your popup.js and it will make all your links open in a new tab when clicked

    Remember to declarer the "tabs" permission in the manifest.json

    window.addEventListener('click',function(e){
      if(e.target.href!==undefined){
        chrome.tabs.create({url:e.target.href})
      }
    })
    

提交回复
热议问题