Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 21st, 2007, 1:50 PM   #1
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 329
Rep Power: 3 kruptof is on a distinguished road
download dialog on button click

Does any body know whether it's possible to display the download dialog box, when the user clicks a button, if so can you show me the code or just explain how to go about it.

Edit: this is in javascript
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Jun 10th, 2007, 4:21 AM   #2
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
Technically it's up to the browser when (and if ever) it displays the download dialog box. Most browsers will do something like it when they find they're trying to load something they can't display themselves or with help, based on the MIME type of what's coming in. So really what you want to do is point the browser at the data to be downloaded, and provided a link to the file where you want a button works, that's no problem.

A trivial version of this that probably won't be exactly what you're after but might form part of the basis for it could be:

<INPUT type="button" onClick="document.location.href = somefile.zip" ...>

As usual with my code examples that's very minimal and I haven't actually tested it but that's the general idea - just convince the browser to try to start loading the file. A word of warning though - not all browsers run JavaScript so while a simple link would do the job for everyone, this will shut out some users. This is probably not as significant as it used to be, but I for one do find myself using elinks from time to time and I'm sure I'm not the only one!

There are two ways to do something similar in a way that works for everyone; one is a link that is an image that looks like a button - you can use its onMouseOver and onClick events to animate it to make it really convincing and if it's still essentially a simple hyperlink and you supply some alt text for the image it'll work for everyone. Another option is to use a form that submits to a CGI that produces the data - this should work for everyone too. For example, lynx won't handle the button with onClick (no JavaScript) but it does handle Submit, which will be rendered as a button in most browsers but handled in sensible other ways by browsers that don't do buttons.

I haven't done any serious web development in years and generally like to keep things as minimal as possible for portability so I hope this isn't creaking and ancient information now! If I was faced with this challenge, to be honest I'd just use a text link that would work for everyone and maybe try to tart it up with some CSS to make it look nicer where that was supported. I got really sick of trying to make clever hacks work in IE as well as standard browsers a good while ago, which is why my knowledge of 'fancy' web development might be aging ungracefully these days.

Anyway, hope this helps.
__________________
"I'm not a genius. Why do I have to suffer?"
mackenga is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Avoid default dialog box for file download? java_roshan Other Web Development Languages 1 Sep 12th, 2006 9:38 PM
Problem Associated with Vector Source code buggytoast Java 3 Apr 2nd, 2006 5:41 AM
Button click Heba PHP 1 Mar 1st, 2006 6:08 AM
How to to do this using Win32 API? csharp C++ 4 Nov 1st, 2005 5:22 AM
Automate button click from C# bobfox C# 2 Sep 8th, 2005 9:55 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:37 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC