JS Download Bullet Box blocked solution

Source: Internet
Author: User

JS Download Bullet Box blocked solutionWord 311Read 0Reviews 0like 0Summarize
  1. Simple usage for early downloads:window.open(downloadUrl)
  2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.