March 13, 2024

Chrome Extension: Popup with clickable links

I share here some recent learning about how to make links in the popup of Chrome extension directly clickable.

Problem description

In the Popup window of a Chrome extension, the links are not directly i.e with normal left-mouse-button click clickable.
If you left-click on a link in the popup nothing happens.

Solution


It requires jquery
  • Add to popup.html in the head section
    <script src="jquery-3.7.1.min.js"></script>
  • Add to popup.js
     $('body').on('click', 'a', function(){
            chrome.tabs.create({url: $(this).attr('href')});
            return false;
        });

I have implemented it like this in my Confluence Chrome Extension.
You can then click directly on the search result links to open the corresponding page.



No comments:

Post a Comment