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

前端 未结 9 634
挽巷
挽巷 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条回答
  •  -上瘾入骨i
    2020-12-04 17:16

    A bit more concise and actual syntax in 2020:

    document.addEventListener('DOMContentLoaded', () => {
      const links = document.querySelectorAll("a");
    
      links.forEach(link => {
        const location = link.getAttribute('href');
        link.addEventListener('click', () => chrome.tabs.create({active: true, url: location}));
      });
    });
    

提交回复
热议问题