Search code examples
node.jsbrowserhyperlinkelectronhref

How to let electron app open all links started with "http://" or "https://" and with target="_blank" open in browser instead in app


How to let electron app open all links beginning with "http://" or "https://" and at the same time with target="_blank" open in browser instead in app

I want it without additional modules like node-open

(sry for my English, google translator)


Solution

  • const shell = nodeRequire('electron').shell
    
    $(document).on('click', 'a[href^="http"][target="_blank"]', function (event){
        event.preventDefault();
        shell.openExternal(this.href);
    });
    

    is working as well, but only if I click on link by left button, but if I click by wheel, it do shit....

    so new queston: How can I open link in external browser if I click by wheel?