Home » Javascript » create a download link with Javascript

create a download link with Javascript

Posted by: admin November 1, 2017 Leave a comment


I currently have the following html:

<p>Your download will begin shortly. If it doesn't,
      <a id="downloadlink" href="Downloads\Run_Hide_Fight.mp4">click here</a>. 

In my javascript, I have the following:

<script type="text/javascript">
    window.onclick= function() {
        window.location= document.getElementById('downloadlink').href;

However, in IE8 and above, instead downloading the file, the file is open directly to my media player. I would like it the file to be downloaded but not open up automatically based on the users default media player.

I hope by updating what i am lookig for is clearer on what I am trying to achieve

   function submit(){