Jump to content

initiate a file download using javascript


c_shelswell

Recommended Posts

Hi I need to start a file downloading using javascript. I had been using php's header but i'm using ajax to collect a users email and it doesn't appear to work anymore. So i was hoping after my page had been called succesfully i could use javascript to start the download?

 

I've tried window.open() which works fine but the firefox pop up stopper blocks it first is there a way to get round this?

 

Cheers

Link to comment
Share on other sites

You can't.  You must load another window to push the download to the user.  Your best bet is to either open a DIV that has a link to the file that the user can right click and download or use a PHP redirect to a new page.

 

Keep in mind that JS can't call to the server to get the file, so you can't really expect it to be able to offer the file up.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.