Launch download in the same tab without opening new tab or window in Javascript

后端 未结 4 547
野趣味
野趣味 2020-12-13 06:38

I am using this javascript function to launch download

function startDownload(url) {
   window.open(url, \'Download\');
}

It works, but i

4条回答
  •  忘掉有多难
    2020-12-13 07:27

    window.open will open a new window \ tab (depending on user preferences) ... to just download the file use

    window.location.href = url;
    

    You can use this if the url returns a downloadable file rather than a web page

提交回复
热议问题