开发者

Download file after time from page load?

开发者 https://www.devze.com 2023-03-23 09:18 出处:网络
i have an exe url that i want to download after 2 sec from page load: like this: var handle = 0; function Download() {

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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消