Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a javascript download link work?

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.

like image 610
Exitos Avatar asked Feb 01 '11 15:02

Exitos


2 Answers

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.

like image 158
BiAiB Avatar answered Oct 22 '22 14:10

BiAiB


Download location can be a url-rewritten path. This mean that maybe some parameters are given with HTTP Post and some HTTP handler in the Web server or web application may be getting some arguments from the HTTP request and write file bytes to an HTTP response, which absolutely hides where the file is located in the actual server's file system.

Maybe this is what's behind the scenes and prevents you to know the file location.

For example, we can have this: http://mypage.com/downloads/1223893893

And you requested an executable like "whatever.exe" for downloading it to your hard disk. Where's the "http:/mypage.com/downloads/whatever.exe"? Actually, it doesn't exist. It's a byte array saved in a long database in some record, and "mypage" web application handles a request for a file that's identified as "1223893893" which can be a combination of an identifier, date time or whichever argument.

like image 22
Matías Fidemraizer Avatar answered Oct 22 '22 14:10

Matías Fidemraizer