JS Download Bullet Box blocked solutionWord 311Read 0Reviews 0like 0Summarize
- Simple usage for early downloads:
window.open(downloadUrl)
- Download the box will be blocked, the solution is to use a form to achieve
Jquery version, multiple downloads Prevent, add more formif($(' #_downloadWin '). length >0) { $(' #_downloadWin '). attr (' action ', URL); $(' #_downloadWin input '). val (path);}Else{//Parameters add hidden fields in the form (<inputtype="Hidden"/>) $ (' body '). Append ($ (' <form id="_downloadwin"action="${url}"target="_blank"Method="Get"><input name="Path" type="Hidden"Value="${path}"/></form> ')); } $(' #_downloadWin '). submit ();
version//javascript varf =Document. createelement ("Form");Document. Body.appendchild (f);vari =Document. createelement ("Input"); I.type ="Hidden"; F.appendchild (i); I.value ="5"; I.name ="Price"; F.action ="Aa.asp";//Download the URL addressF.submit ();
Problem description and Solution
The early downloading of files was accomplished directly using window.open(downloadUrl)
this simple and crude method.
But by now (2016.05.17), window.open has been blocked by most of the mainstream browsers, as shown below, you need to manually click once to allow the link to open. This greatly reduces the friendly interaction.
Paste_image.png
You need to find a new solution, use form elements to download, note that the form's target is set to _blank* in a new window, so it doesn't affect this page
JS Download Bullet Box blocked solution