Home » Javascript » create a download link with Javascript

create a download link with Javascript

Posted by: admin November 1, 2017 Leave a comment

Questions:

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>. 
</p>

In my javascript, I have the following:

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

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

Answers:
<script>
   function submit(){
     window.location.replace("http://stackoverflow.com/video.avi");
   }
</script>