startDownload Method

This topic documents a feature of Binary Behaviors, which are obsolete as of Internet Explorer 10.

Downloads the specified file.


download.startDownload(sUrl, fpCallback)


sUrl Required. A String that specifies the location of the file to download.
fpCallback Required. A function pointer that specifies the code to execute after the download is complete.

Return Value

No return value.


The callback function pointer takes a single parameter. When a file downloads successfully, the file contents are passed as the parameter and are accessible in script.

The startDownload method returns only the content of text documents. If a different document format is downloaded, the format is returned, but the file content is not.

Note  To use the startDownload method with Microsoft Visual Basic Scripting Edition (VBScript), you must use the GetRef function to obtain a function pointer. The function pointer can then be passed to startDownload.

The following sample code shows a callback function.

// The callback function accepts one parameter.
function fnCallBack(vData){
   /* vData stores the downloaded file content.
      The content can be split into an array,
      written to another file, or processed in a form.
   var aData=vData.split("\n");


This example uses the startDownload method to begin downloading a file when the user clicks the link. The specified callback function, onDownloadDone, is notified when the download is complete.


<MSIE:DOWNLOAD ID="oDownload" STYLE="behavior:url(#default#download)" />

    function onDownloadDone(s) { alert (s); }

<P>Click <A HREF="javascript:oDownload.startDownload('download.htm', 
onDownloadDone)">here</A> to download this page.

Code example:

This example demonstrates using the download behavior with VBScript.


    Function onDownloadDone(s) 
        MsgBox s
    End Function

<IE:DOWNLOAD ID="oDownload" STYLE="behavior:url(#default#download)" />

onclick="vbscript:oDownload.startDownload 'downloadvb.htm', GetRef('onDownloadDone')">
Download File</button>

Applies To


Community Additions