从页面加载后的时间下载文件?

时间:2011-07-27 08:16:07

标签: javascript jquery

我有一个exe页面,我想在页面加载2秒后下载:像这样:

    var handle = 0;
    function Download() {
        window.location = "exeUrl";
        clearInterval(handle);
    }
    $(document).ready(function () {
        handle = setTimeout('Download()', 5000);            
    });

NOW :我的问题是window.location会重新加载页面,下载功能会被召回吗?

3 个答案:

答案 0 :(得分:2)

尝试

window.location.href = "exeUrl";

代替。

此外,

setTimeout(Download, 2000);

优先于:

setTimeout('Download()', 2000);

答案 1 :(得分:1)

可能像

function Download() {
    window.open("exeUrl");
    clearInterval(handle);
}

弹出窗口拦截器会干扰:(

或者您可以添加类似

的内容
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);
}

答案 2 :(得分:0)

  var handle = false;
    function Download() {
        if(handle)return;
        handle=true;window.location = "exeUrl";
    }
    $(document).ready(function () {
        setTimeout('Download()', 5000);            
    });

应该有效:)

相关问题