Opening a browser window from an <a> in the app?


#1

I would like to create a link from the app to the website. I Have tried to read up on Browser Window but there is no information to but the code.

Information available on the FAQ :

var BrowserWindow = require(‘browser-window’);

var win = new BrowserWindow({ width: 800, height: 600, show: false });
win.on(‘closed’, function() {
win = null;
});

win.loadUrl(‘https://github.com’);
win.show();

MY HTML:

More Info

Any help would be great - Thanks


#2

Could you clarify what it is you’re trying to do?

What does your project currently have, and what is it specifically that you are trying to do?


#3

you could create a browser window in the main process and then open another one from the renderer process with remote…
your question is not so clear though


#4

I just want to have a more info button in a A TAG that will open up a browser window not another electron window.

Cheers


#5
 <div class="content-wrapper">

   <a id="demo" onclick="myFunction()"><button  class="btn btn-large btn-default moreInfo-Link-button">More Info</button></a> 

</div>


                        <script>
                        function myFunction() {
                            const remote = require('electron').remote;
                        const BrowserWindow = remote.BrowserWindow;

                        var win = new BrowserWindow({ width: 800, height: 600 });
                        win.loadURL('www.google.com');
                        }
                        </script>

I have tried this , it works but making a electron window not a Browser window.


#6

Something like this ?

var shell = require('electron').shell;
//open links externally by default
$(document).on('click', 'a[href^="http"]', function(event) {
    event.preventDefault();
    shell.openExternal(this.href);
});

The BrowserWindow really is an electron browser window.


#8

Hi i got this working but opens the electron window strait on application , I was looking to open say a browser like chrome with the intended website without affecting window im working in.


#9

That’s why I proposed shell.openExternal.

openExternal delegate to the OS wich program to open whatever ressource you pointed to.


Proper way to open new window
#11

HI there just cracked it with a bit of Java:

   <a onclick="myFunction()"><button  class="btn btn-large btn-default moreInfo-Link-button">More Info</button></a> 

</div>


                        <script>
                        function myFunction() {
                            var shell = require('electron').shell;
                         event.preventDefault();
                          shell.openExternal('https://github.com');


                        }
                        </script>

Thanks for the Help :slight_smile:


#12

for those like myself who were looking to use an HTML string instead of a URL, see this stackoverflow post


#13

worked like a charm! Just what I needed. I’m using this code to open local pdf files.

thanks!