문제

Internet Explorer에서 파일의 자동 다운로드를 초기화하려면 어떻게해야합니까?

예를 들어, 다운로드 페이지에서 다운로드 링크가 나타나고 "다운로드가 자동으로 시작되지 않으면 .... 등을 시작하지 않습니다"라는 메시지를 원합니다. 다운로드는 페이지로드 직후에 시작해야합니다.

Firefox에서는 쉽습니다. 헤더에 메타 태그 만 포함하면됩니다. <meta http-equiv="Refresh" content="n;url"> 여기서 n은 초 수입니다 url 다운로드 URL입니다. 인터넷 익스플로러에서는 작동하지 않습니다. 인터넷 익스플로러 브라우저 에서이 작업을 어떻게 만들려면?

도움이 되었습니까?

해결책

Sourceforge an <iframe> 요소 src="" 다운로드 할 파일을 가리키는 속성.

<iframe width="1" height="1" frameborder="0" src="[File location]"></iframe>

(부작용 : 리디렉션, JavaScript 없음, 원래 URL은 변경되지 않았습니다.)

다른 팁

싫어하다 사이트가 너무 많이 다운로드 할 때 좋은 오래된 링크 대신 해킹을 사용하십시오.

Dead Simple 버전 :

<a href="file.zip">Start automatic download!</a>

효과가있다! 모든 브라우저에서!


일반적으로 인라인으로 표시되는 파일 (예 : 이미지)을 다운로드하려면 HTML5에 download 파일의 다운로드를 강요하는 속성. 또한 파일 이름을 무시할 수 있습니다 (더 좋은 방법이 있지만):

<a href="report-generator.php" download="result.xls">Download</a>

"감사"페이지가있는 버전 :

다운로드 후 "감사"를 표시하려면 다음을 사용하십시오.

<a href="file.zip" 
   onclick="if (event.button==0) 
     setTimeout(function(){document.body.innerHTML='thanks!'},500)">
 Start automatic download!
</a>

그것에 기능합니다 setTimeout 더 발전하고 예를 들어 Ajax를 통해 전체 페이지를 다운로드 할 수 있습니다 (그러나 페이지에서 멀리 떨어지지 마십시오 - 터치하지 마십시오. window.location 또는 다른 링크를 활성화).

요점은 다운로드에 대한 링크가 실제, 복사, 드래그, 다운로드 가속기에 의해 차단 될 수 있다는 것입니다. :visited 색상, 브라우저 재시작 후 페이지가 열려있는 경우 다시 다운로드하지 않습니다.

그것이 내가 imageOptim에 사용하는 것입니다

나는 비슷한 문제가 있었고 위의 솔루션 중 어느 것도 나에게 효과가 없었습니다. 여기 내 시도가 있습니다 (jQuery 필요) :

$(function() {
  $('a[data-auto-download]').each(function(){
    var $this = $(this);
    setTimeout(function() {
      window.location = $this.attr('href');
    }, 2000);
  });
});

사용법 : 호출 된 속성 만 추가하십시오 data-auto-download 문제의 다운로드를 가리키는 링크에 :

<p>The download should start shortly. If it doesn't, click
<a data-auto-download href="/your/file/url">here</a>.</p>

모든 경우에 작동해야합니다.

최근에 다음 스크립트를 페이지에 배치하여 해결했습니다.

setTimeout(function () { window.location = 'my download url'; }, 5000)

나는 메타 리프레 쉬가 더 좋을 것이라는 데 동의하지만 그것이 효과가 없다면 어떻게해야합니까?

간단한 jQuery 가이 문제를 해결했습니다.

$(function() {
   $(window).bind('load', function() {
      $("div.downloadProject").delay(1500).append('<iframe width="0" height="0" frameborder="0" src="[YOUR FILE SRC]"></iframe>'); 
   });
});

내 html에서 나는 단순히 가지고 있습니다

<div class="downloadProject"></div>

이 모든 것이 2 초 반을 기다린 다음 다운로드하려는 파일을 참조하는 iframe과 함께 div를 추가하십시오. iframe이 페이지에 업데이트되면 브라우저가 파일을 다운로드합니다. 그렇게 간단합니다. :디

이것이 제가 일부 사이트에서 사용하는 것입니다 (jQuery 필요). :

$(document).ready(function() {
    var downloadUrl = "your_file_url";
    setTimeout("window.location.assign('" + downloadUrl + "');", 1000);
});

파일은 1 초 후에 자동으로 다운로드됩니다.

나는 이것을 사용했고, 작동하는 것처럼 보이며 단순한 JS, 프레임 워크가 없습니다.

Your file should start downloading in a few seconds. 
If downloading doesn't start automatically
<a id="downloadLink" href="[link to your file]">click here to get your file</a>.

<script> 
    var downloadTimeout = setTimeout(function () {
        window.location = document.getElementById('downloadLink').href;
    }, 2000);
</script>

참고 : 페이지가로드되는 순간 타임 아웃이 시작됩니다.

Chrome, Firefox 및 IE8 이상에서 작동합니다.

var link = document.createElement('a');
document.body.appendChild(link);
link.href = url;
link.click();

확인하고 찾았습니다. 버튼에서 작동합니다. onclick 이벤트를 작성하여 태그 또는 입력 버튼을 앵커 버튼을 통해 클릭합니다.

onclick='javascript:setTimeout(window.location=[File location], 1000);'

파일을 제공하십시오 없이 캐시가없는 헤더! IE는 사용자가 먼저 저장하지 않고 다운로드를 "열"하려고 시도하는 경우 문제가 있습니다.

뿌리로 돌아가서 나는 이것을 사용한다 :

<meta http-equiv="refresh" content="0; url=YOURFILEURL"/>

아마도 WC3은 일치하지 않지만 모든 브라우저에서 완벽하게 작동하며 HTML5/JQuery/JavaScript는 없습니다.

인사 톰 :)

하나 더 :

var a = document.createElement('a');
a.setAttribute('href', dataUri);
a.setAttribute('download', filename);

var aj = $(a);
aj.appendTo('body');
aj[0].click();
aj.remove();

이것은 모든 브라우저에서 나를 위해 작동하는 것처럼 보였습니다.

 <script type="text/javascript">
    window.onload = function(){
     document.location = 'somefile.zip';
    }
    </script>

나는 이것이 당신에게 효과가있을 것이라고 생각합니다. 그러나 방문객들은 더 많은 시간을 보내지 않고 몇 초 안에 무언가를 얻었으므로 다시 사이트를 방문하게됩니다.<a href="file.zip" onclick="if (event.button==0) setTimeout(function(){document.body.innerHTML='thanks!'},500)"> Start automatic download! </a>

a를 사용하여 다운로드를 트리거하려는 사람들을 위해 동적 링크 브라우저에서 일관되게 작동하는 것은 까다 롭습니다.

IE10+ PDF 다운로드에 문제가 있었고 사용했습니다. @dandavis ' download 기능 (https://github.com/rndme/download).

IE10+ 필요 msSaveBlob.

I hope this will works all the browsers. You can also set the auto download timing.

<html>
<head>
<title>Start Auto Download file</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
$(function() {
$('a[data-auto-download]').each(function(){
var $this = $(this);
setTimeout(function() {
window.location = $this.attr('href');
}, 2000);
});
});
</script>
</head>
<body>
<div class="wrapper">
<p>The download should start shortly. If it doesn't, click
<a data-auto-download href="auto-download.zip">here</a>.</p>
</div>
</body>
</html>

Demo Here

Nice jquery solution:

jQuery('a.auto-start').get(0).click();

You can even set different file name for download inside <a> tag:

Your download should start shortly. If not - you can use
<a href="/attachments-31-3d4c8970.zip" download="attachments-31.zip" class="download auto-start">direct link</a>.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top