I want to run a JNLP file on page load using javascript.
Internet explorer runs JNLP without any problem, but Chrome downloads JNLP.
But if I click on link manually chrome runs JNLP, also.
Is there a solution to run a JNLP on page load without any manual click, on chrome?
Here is my example code:
<head>
<script>
function codeAddress() {
document.getElementById('mylink').click();
}
window.onload = codeAddress;
</script>
</head>
<body>
<a id="mylink" target="_self" href="http://localhost/projects/myjnlp.jnlp">go</a>
</body>
Hi this is not a matter of correct code but a matter of Chrome configuration. We have a similar problem with an application we rolled out for one of our customers. JNLP files are not trusted by default thus the JNCP file is downloaded by Chrome and then the user is asked whether to keep or discard the file.
Once the user keeps the file we are able to choose "Always Open Files of This Type" in the menu of the downloaded item. See the following screenshot for reference:

In our case the applications runs on Intranet we can help our users configuring chrome correctly. In your case however I suggest that you use jQuery to determine the browser and show an instruction box on the lower left corner of the window (where the download item will show up).
Assuming you have a hidden DIV on the lower left corner of your page and you have already included the jQuery browser plugin:
$.browser.chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase());
if($.browser.chrome){
$('#chromeInstructions').show();
}
Found a simple solution. Prefix the href attribute of the <a> tag with the jnlp: scheme/protocol, like href="jnlp:XXX". For example, based on the OP's example, this works:
<a id="mylink" href="jnlp:http://localhost/projects/myjnlp.jnlp">go</a>
Tested on Chrome v89.0.4389.72.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With