Answered by:
Open URL from javascript without Browser Window

Question
-
Hi
HTML Code : On clicking on this below link (i.e. JNLP URL), Notepad will open.
<a href="https://docs.oracle.com/javase/tutorialJWS/samples/deployment/NotepadJWSProject/Notepad.jnlp">Launch Notepad Application</a>
Javascript Code : what we want here is same functionality to open URL(i.e. Notepad) from Javascript.
Currently we are trying to open url by window.open() Javascript method, Which opens URL in separate window. It means that Javascript first opens another browser window for a fraction of seconds and then opens notepad(another window).
Again what we want here is that Browser window which comes for fraction of seconds should not appear and opens the notepad directly as it opens by HTML code from JavaScript code.
Thanks and Regards
Karan
- Edited by karan guleria Friday, January 20, 2017 8:39 AM
Thursday, January 19, 2017 11:50 AM
Answers
-
Hello Karan,
This would be easy to achieve by returning "false" from your event handler and prevent reload. You would stop event propagation with it. The following would be the example ...
<!DOCTYPE html> <html> <head> <script> function openNotepad() { window.location.href="https://docs.oracle.com/javase/tutorialJWS/samples/deployment/NotepadJWSProject/Notepad.jnlp"; return false; } </script> </head> <body> <a href="#" onclick='return openNotepad();'>Open Notepad</a> </body> </html>
or one line example:
<a href="#" onclick='window.location.href="https://docs.oracle.com/javase/tutorialJWS/samples/deployment/NotepadJWSProject/Notepad.jnlp";return false;'>Open Notepad</a>
Hope this helps,
Slava Ivanov
- Edited by Slava Ivanov at Dev Network Monday, January 23, 2017 2:40 PM
- Marked as answer by karan guleria Wednesday, January 25, 2017 12:58 PM
Monday, January 23, 2017 2:24 PM
All replies
-
Hello Karan,
This is probably what you want ...
<a href="#" onclick='window.location.href="https://docs.oracle.com/javase/tutorialJWS/samples/deployment/NotepadJWSProject/Notepad.jnlp";'>Open Notepad</a>
Slava Ivanov
Thursday, January 19, 2017 4:04 PM -
Hi Slava,
I am afraid you misunderstand my query. Let me explain again.
My query is to open below JNLP URL by java script code only. Currently i am trying to open URL in Javascript by window.open() method.
Javascript code : window.open("https://docs.oracle.com/javase/tutorialJWS/samples/deployment/NotepadJWSProject/Notepad.jnlp","_blank");
JNLP URL is : "https://docs.oracle.com/javase/tutorialJWS/samples/deployment/NotepadJWSProject/Notepad.jnlp"
Drawback of this Javascript code is it first opens another browser window for a fraction of seconds and then opens notepad in another window. I want here that first browser window which opens for fraction of seconds should not appear and only Notepad window open.
e.g.
On below HTML Anchor tag, on clicking of link(JNLP URL) notepad will open. we want to open URL same way as HTML code is doing by Javascript code.
HTML Code : <a href= "https://docs.oracle.com/javase/tutorialJWS/samples/deployment/NotepadJWSProject/Notepad.jnlp">Launch Notepad</a>
Regards
Karan
- Edited by karan guleria Friday, January 20, 2017 8:54 AM
Friday, January 20, 2017 8:38 AM -
Karan,
I just put everything in one line as example. You JS code would be ...
window.location.href="https://docs.oracle.com/javase/tutorialJWS/samples/deployment/NotepadJWSProject/Notepad.jnlp";
As simple as that. You may invoke it in your own function or call it from different event handler (other than onClick event). The point is: this JS will not spawn new window, but just redirect you browser window to new URI. As this URI is not HTML page, it will simply keep original page in the browser view and open dialog to invoke Java Notepad.
let me know,
Slava Ivanov
Friday, January 20, 2017 2:02 PM -
Hi Slava,
Many thanks for your reply and for sparing time.
I tried with suggested JS syntax. Though it open Java notepad but drawback of this syntax is this it refreshes base page(i.e. calling page) where we use this "window.location.href" syntax.
Same problem we face with "href" attribute of anchor HTML control . It also refreshes base page.
What we want that Java notepad will open but base page stay remain as it is , not refresh itself.
Hope it means.
Best Regards
Karan
Saturday, January 21, 2017 4:45 PM -
Hello Karan,
This would be easy to achieve by returning "false" from your event handler and prevent reload. You would stop event propagation with it. The following would be the example ...
<!DOCTYPE html> <html> <head> <script> function openNotepad() { window.location.href="https://docs.oracle.com/javase/tutorialJWS/samples/deployment/NotepadJWSProject/Notepad.jnlp"; return false; } </script> </head> <body> <a href="#" onclick='return openNotepad();'>Open Notepad</a> </body> </html>
or one line example:
<a href="#" onclick='window.location.href="https://docs.oracle.com/javase/tutorialJWS/samples/deployment/NotepadJWSProject/Notepad.jnlp";return false;'>Open Notepad</a>
Hope this helps,
Slava Ivanov
- Edited by Slava Ivanov at Dev Network Monday, January 23, 2017 2:40 PM
- Marked as answer by karan guleria Wednesday, January 25, 2017 12:58 PM
Monday, January 23, 2017 2:24 PM