i have an exe url that i want to download after 2 sec from page load: like this:
var handle = 0;
function Download() {
window.location = "exeUrl";
clearInterval(handle);
}
$(document).ready(function () {
handle = setTimeout('Download()', 5000);
});
NOW: My problem is window.location will reload the 开发者_运维知识库page and download function will be recall?
Try
window.location.href = "exeUrl";
instead.
Also,
setTimeout(Download, 2000);
is preferred to:
setTimeout('Download()', 2000);
maybe something like
function Download() {
window.open("exeUrl");
clearInterval(handle);
}
popup blocker will interfere here :(
Or you could add something like
function Download() {
var ifr = document.createElement('iframe');
ifr.src='exeUrl';
ifr.style.width = '1px';
ifr.style.height = '1px';
ifr.style.border= 'none';
ifr.style.position= 'absolute';ifr.style.margin= '-20px -20px';
document.body.appendChild(ifr);
clearInterval(handle);
}
var handle = false;
function Download() {
if(handle)return;
handle=true;window.location = "exeUrl";
}
$(document).ready(function () {
setTimeout('Download()', 5000);
});
that should work :)
精彩评论