Make a link from Electron open in browser

前端 未结 6 1387
庸人自扰
庸人自扰 2020-12-15 15:21

Is there any (simple/built-in way) to open a new browser (I mean default OS browser) window for a link from Electron instead of visiting that link inside your Electron app ?

6条回答
  •  [愿得一人]
    2020-12-15 16:23

    There's a much better and simpler way, than what @Marcelo proposed, yet easier to implement for all links at once to what @zianwar proposed.

    const shell = require('electron').shell;
    
    // assuming $ is jQuery
    $(document).on('click', 'a[href^="http"]', function(event) {
        event.preventDefault();
        shell.openExternal(this.href);
    });
    

    NOTE: Requires jQuery.

提交回复
热议问题