473,546 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple file link or button doesnt work

pd
guys,

in my web app, i have a simple download button and a href which points
to a file on my server, when the user clicks on the button or the
link, the file should simply be downloaded to the users machine. now
this file is a postgres backup file with the .backup extension.

now when i use the button, in FF the file download button pops up and
i can save the file, i can also right click the href and go save link
as. and it works fine.

but when i use the button or link in IE, it simply opens up the file
in IE as text and displays a bunch a garbage. now the user needs to be
able to download the file and not view it. also on the href link, when
the right clicks and goes save target as IE automatically adds
the .html extension to the file. now i dont have the .backup extension
in my registered file types.

just to end, my href is, <a href="http://localhost:8080/Backup/
Today.backup">D ownload</aand the button is,
<input type="button" value="Download " onclick="locati on.href('http://
localhost:8080/Backup/Today.backup')" >

please help me. all i want the user to be able to do is, to download
the file, and they can either go right click and save target or just
click on it and the download dialog should pop up. thanks.

Jun 1 '07 #1
3 2447
Lee
pd said:
>please help me. all i want the user to be able to do is, to download
the file, and they can either go right click and save target or just
click on it and the download dialog should pop up. thanks.
That's not the way browsers are supposed to work. The browser
should display the file that you click on in the window if it
knows how. Only if it doesn't know how (or knows that it isn't
safe to try), should it offer to download the contents. Unless,
of course, the server tells the browser that the file should
take some other action.
--

Jun 1 '07 #2
Lee said the following on 5/31/2007 10:04 PM:
pd said:
>please help me. all i want the user to be able to do is, to download
the file, and they can either go right click and save target or just
click on it and the download dialog should pop up. thanks.

That's not the way browsers are supposed to work. The browser
should display the file that you click on in the window if it
knows how. Only if it doesn't know how (or knows that it isn't
safe to try), should it offer to download the contents. Unless,
of course, the server tells the browser that the file should
take some other action.
Or, the user has explicitly told the browser how to handle a particular
file. IE and FF both have that setting available to the user.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 1 '07 #3
It's true that browsers have various sets of "default behaviors" for
various mimetypes:

- some known mimetypes will by default be displayed inside the
browser.
- some known mimetypes will by default be downloaded to the desktop.
- when no mime type is sent, and the browser doesn't recognize the
file type, then anything could happen, and i suspect that's what's
happening with your backup file.

You can override the download vs show-in-browser "default behavior",
thru the "content-disposition" http header field:

http://www.ietf.org/rfc/rfc2183.txt

Try configuring your http server so that .backup files will have a
correct mime type if one is defined, but more relevantly, try to make
sure your server sends an additional HTTP Header:

Content-Disposition: attachment; filename=MYFILE .backup

Flickr.com has some good examples of overriding a browser's default
behavior of loading images inside the browser window and forcing a
download thru the Content-Disposition header. If you have a flickr
account, look at a picture's "all sizes" page, and click the
"Download" link. It's a simple HREF Anchor Tag, but the HTTP Response
does set the Content-Disposition header, here's an excerpt from a
response to a click on one of my images:

HTTP/1.0 200 OK
Date: Fri, 01 Jun 2007 08:12:34 GMT
Server: Apache/2.0.52 (Red Hat)
Content-Disposition: attachment;
filename=516875 174_4be52f4dbd_ b.jpg <---- LOOK RIGHT HERE
Pragma: no-cache
Expires: 0
Last-Modified: Sun, 27 May 2007 23:30:50 GMT
Accept-Ranges: bytes
Content-Length: 396060
Content-Type: image/jpeg <--- ALWAYS A GOOD IDEA TO SET PROPER
MIMETYPE AS Content-Type header value
X-Cache: MISS from photocache3.fli ckr.mud.yahoo.c om

On May 31, 9:55 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
Lee said the following on 5/31/2007 10:04 PM:
pd said:
please help me. all i want the user to be able to do is, to download
the file, and they can either go right click and save target or just
click on it and the download dialog should pop up. thanks.
That's not the way browsers are supposed to work. The browser
should display the file that you click on in the window if it
knows how. Only if it doesn't know how (or knows that it isn't
safe to try), should it offer to download the contents. Unless,
of course, the server tells the browser that the file should
take some other action.

Or, the user has explicitly told the browser how to handle a particular
file. IE and FF both have that setting available to the user.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptT oolbox.com/bestpractices/

Jun 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5817
by: peetm | last post by:
I'd like to write to a log whenever a visitor to my site downloads a file. So, I'd like the link they click to be to a php 'page' that returns the file. Don't know how to do that! Side Question ... Presumably, the dialog that you see when you download a binary (asking for a 'Save As...' file name) is put up by your browser when it...
13
4735
by: Samantha Smit | last post by:
Hi, I am trying to create a simple asp page that has one command button that updates a database. The URL of the page is like this: http://MyServer.com/Update.asp?UserName=Tom My asp code is like this: %@ Language=VBScript %> <!--#include file="includes/openconnection.asp"-->
2
1104
by: Ed | last post by:
I'm rather new to ASP .Net, so I appologize in advance if I'm asking a dumb question here. I've been searching all over the place for an answer and haven't found a single one. I'm working on a form that gives the user a file control to upload a file from their machine to my server. With this file control are two buttons; one marked...
2
1862
by: iwdu15 | last post by:
hey, i was wondering if 1) anyone could tell me whats wrong with my code, i did a little fixing to the msdn version fo this, or 2) how to make a simple program that will connect and listen for connections async. if the user pushes the selected buttons. i just want a program that connects to another computer on the port and IP address selected...
4
1754
by: Duncan | last post by:
Hi I'm learning c# 2.0 as I feel I need to be able to switch between vb & c#, I'm just starting with a few simple examples and I've come across a problem. I've got two forms ones an MDI parent & ones a child form. I've put this code into a menustrip on the parent form private void maintainClientsToolStripMenuItem_Click(object sender,...
2
8359
by: Evan | last post by:
Hey, I posted this yesterday, but no one had any ideas? C'mon now, I know this isn't that hard, i'm just a little new to javascript, and I can't quite figure this out. I searched and searched to try and find the answer to this, but I had no luck anywhere. It's a little different situation than I found anywhere else. I would simply put...
6
2026
by: Jim M | last post by:
I've been distributing a fairly mature, very specific MS Access application to end users in small offices of colleges for several years now. This is a part-time venture and low volume operation- this is somewhat of a hobby for me. Many of my end users are computer phobic and get little support from their IT departments. It is a split database...
0
1414
by: anwarulhuq | last post by:
I have placed Edit-Update-Cancel Link button from Properties builder of the Data Grid. Its working but the problem what im facing is.. It doesnt work till i click for two times. Link button should work for only one click right. Please help me out to solve this.
2
3639
by: Peted | last post by:
I have 6 radio buttons in a column with a single line text box next to each rb. is there a general straightforward way to link a radio button to the textbox next to it. I want to be able to click on any of the rb in the column and from that click derive the contents of the textbox next to it that it is "linked" to.
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7698
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7794
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.