Stack Diego
Stack Diego

Reputation: 1337

File download with javascript/jquery

I'm trying to download an apk file from my webapp using a tablet.

<a href="#" data-role="button" id="loginButton" class="pulsantino">Login</a>

$("#pulsanteLogin").live("click",function(){
     alert("1");
     window.location.href = 'http://xx.yy.zz.www:1234/staticResources/Myapp_version.apk';
     alert("2");
}

I know for sure that the url is correct (launching it from the browser will correctly start file download), but when i click on the button i get no error and no file download. I get both the alerts for '1' and '2'.

I've tried also with

location.href = 'url';

and

window.location = 'url';

Ideas?

Upvotes: 1

Views: 697

Answers (2)

Domenic Fiore
Domenic Fiore

Reputation: 544

Are you using a newer version of jQuery than 1.7? .live() got deprecated, and .on() is now the way to go. http://api.jquery.com/on/

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live(). Source: http://api.jquery.com/live/

Upvotes: 0

Robin van Baalen
Robin van Baalen

Reputation: 3651

Maybe this is too obvious, but why dont you just use a regular link like this directly:

<a href="http://xx.yy.zz.www:1234/staticResources/Myapp_version.apk" data-role="button" id="loginButton" class="pulsantino">Login</a>

Are you executing more code which requires the dynamic change of this link's href attribute?

Upvotes: 1

Related Questions