javascript下载链接如何工作? [英] How does a javascript download link work?
问题描述
我一直在使用Microsoft Technet网站,您可以通过点击页面上的链接下载ISO文件。元素是这样的:
< a href =javascript:void(0)onmouseout =HideToolTip()
onmouseover =ShowToolTip(event,'点击这里下载')
onclick =javascript:RunDownload('39010 ^ 313 ^ 164',event)
class =detailsLink >下载和LT; / A>
我无法找到 RunDownload()
方法。我想知道它有可能做什么。我的意思是通常当我提供一个链接给某人下载我提供一个锚点:
< a href =www .foo.com中/ mymp3.mp3\" >下载和LT; / A>
但是这个脚本在做什么是不同的?因为即使我跑了'Fiddler',我看不到实际的下载位置。
没有这样的东西一个javascript下载链接。 Javascript可以打开一个新窗口,或者模拟一个链接的点击。
你必须找到的是这个点击触发的功能是哪个url将导致。 p>
这里是一个如何做的例子:
假设我们有一个:
< a id =download> download这里§§§< / a>
然后这个jQuery代码:
$('#download')。click(function(){
window.location.href ='http://example.org/download/ISO.ISO';
});
将重定向到URL http://example.org/download/ISO.ISO 。这个url是否开始下载取决于HTTP标头和浏览器,而不是在javascript上做什么。
I've been using the Microsoft Technet site and you can download the ISO files by clicking a link on the page. The element is like this:
<a href="javascript:void(0)" onmouseout="HideToolTip()"
onmouseover="ShowToolTip(event,'Click here to download.')"
onclick="javascript:RunDownload('39010^313^164',event)"
class="detailsLink">Download</a>
I wasn't able to find the RunDownload()
method in the scripts. And I wondered what it is likely to do. I mean usually when I provide a link for someone to download I provide an anchor to it:
<a href="www.foo.com/mymp3.mp3">download</a>
But this is working differently what is the script doing? Because even when I ran 'Fiddler' I wasn't able to see the actual download location.
there's no such thing as a "javascript download" link. Javascript can open a new window, or simulate a click on a link.
What you have to find is which url the function triggered by this click will lead to.
here's an example of how to do it:
Suppose we have a:
<a id="download">download Here §§§</a>
then this jQuery code:
$('#download').click( function() {
window.location.href = 'http://example.org/download/ISO.ISO';
} );
will redirect to the URL http://example.org/download/ISO.ISO. Whether this url starts a download or not depends on HTTP headers and your browser, not on what javascript do.
这篇关于javascript下载链接如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!