neutralinojs
neutralinojs copied to clipboard
Anchor tags with target attribute are not being loaded
Expected Behaviour
On clicking the link, the corresponding website/app should be opened in default browser.
Actual Behaviour
On clicking the link, neutralino app doesn't respond.
Steps to Reproduce the Problem
-
npm install @neutralinojs/neu
-
npx @neutralinojs/neu create .
- open
/resources/index.html
and add the following line<a href="https://neutralino.js.org/">Visit NeutralinoJs !</a>
-
npx @neutralinojs/neu run
- click the link, it opens neutralino.js.org
- open
/resources/index.html
and replace the previous line with<a href="https://neutralino.js.org/" target="blank">Visit NeutralinoJs !</a>
- click the link, it doesn't open anything.
Specifications
- NeutralinoJs Version: 4.3.0
- NeutralinoJs CLI version: 3.2.0
- Platform: Ubuntu 20.04
This is a expected behaviour, since Neutralino doesn't bundle the browser and uses the inbuilt browser's API (webview) for showing html css and js, it doesn't know how to treat that url, other than going to that url.
To open URLs in default browser you need the OS API.
Neutralino.os.open("https://google.com");
So, when target="blank"
is set, shouldn't it by default call Neutralino.os.open("https://google.com");
under the hood ?
No, Neutralino Doesn't touch anything under the hood.
Cool. So, if someone wants a link that needs to be opened externally in web browser, should have to use Neutralino.os.open("https://google.com");
?
Yes, or you can automate this with this simple hack:
Neutralino.events.on("ready", () => {
let anchorLinks = document.querySelectorAll("a")
anchorLinks.forEach((anchorLink) => {
let href = anchorLink.href;
anchorLink.onclick = () => {
Neutralino.os.open(href);
}
anchorLink.href = "#"
})
})
Now you can have a simple anchor link in your html like this:
<a href="https://neutralino.js.org/docs">Docs</a> ·
<a href="https://www.youtube.com/watch?v=txDlNNsgSh8&list=PLvTbqpiPhQRb2xNQlwMs0uVV0IN8N-pKj">Tutorial</a>
And when click them, it will open in the default browser.
By default, can we get this implemented in the framework itself ? Because some developers just use target="blank"
and this might leave them to write this piece of code by themselves. So, shall I work on putting this in the framework ?
For ex : if some developer is copying a html file which has <a href="https://neutralino.js.org/" target="blank">Visit NeutralinoJs !</a>
he has to write extra lines.
can i work on this issue
@harshithgupta28 I faced this issue and raised it. A fix was already suggested, check here. Let me know if you have any other idea to be implemented in your mind.