Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can javascript prompt a download?

Status
Not open for further replies.

aepheus

Programmer
Mar 22, 2007
3
US
Let me give you the situation first off.
I'm creating this website with lots of content. Users want to download this content in a convinent way (lets say a text file) for later use.
The content is already being displayed for the user, and is accessible by javascript. Is there a way to have javascript create the text file and prompt the download dialog when a user clicks a button?

I also want this to run without risky internet settings.

Yes it can easily be done with server-side languages. But, that is not what I want. I'm looking to do this without a server call.
 
Do you need it to be cross-browser? If not, and IE-only is fine, you might investigate "execCommand" with the "save" parameter.

If you do, I'd go with server-side.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I havent tried this, but in theory you could parse an variable in the head section of the document.

This means you would have to have a function in the head of your file, which could parse the header("Content-Disposition: , based on a variable.

How you pass that variable is another question though.. I know you can use querystring, maybe use cookies? not sure.. lol.. I would just do this serverside, if possible.

Olav Alexander Mjelde
Admin & Webmaster
 
I'm pretty sure that javascript can at best read the header, it cannot write them. It does need to be cross-browser. I'm thinking that server-side is the best way, was just hoping for a cool javascript implementation.
 
I know you can make JS submit forms, cant it submit URLS too?

It can certannly change the HREF of an url "on the fly" and if it then can press the url afterwards, you can get the download prompt.

If thats possible, which I believe it should be, I believe it would be very basic functionality which should also be supported by most browsers?

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top