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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save as / Open dialog box for Text file link 2

Status
Not open for further replies.

timesign

Programmer
May 7, 2002
53
US
This is probably a standard question, but I cant seem to find enough info on it.
I want to have a list of links to text files which the user can download. I do not want them to open in Internet Explorer. How do I make sure the user gets the Save as / open dialog box for files and that they do not open in IE.

Do I have to code outside of HTML?
My site is in java and there is one folder with all the text files that will be on this page. I was going to make this part of the site in straight HTML, but i can't seem to figure out how to do it in HTML or java.
Thanks
 
Hi mate,

If you can use Coldfusion, check out the following:


If not, do a search for the content-disposition header, this will do what you want.

Hope this helps

Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
If you provide straight links to the .txt files, it is up to the users' browser to interpret what they are. In IE's case (and probably all other modern browsers) it shows the plain text contents in the browser window. So one option is to put a note beside the links asking your guests to right-click and choose save as.

Another option is to have links to .asp files which contain one line specifying an unknown content type, and then the rest is plain text as before. Eg:
Code:
<%
Response.ContentType = &quot;application/force-download&quot;
' or make one up, eg &quot;bla/ignore-this&quot;
%>
This is all plain text from here to end of file..

This should confuse the browser, so that it would go straight to a save/open with dialog. You may also need to mess around with some other headers, but it is all only an option if you have access to server-side script (eg PHP or ASP).

Good luck

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Can anyone please add more to this?
I having the same problem, but I'm not really following the last post.
thanks.
 
THe gist is that there's no real of doing this with straightforward HTML.

A browser decides how to handle a page by it's MIME type (OK, there are a few exceptions, but this is the rule).

When you go to a webpage, this is what you're browser receives before the html code (here are the tek-tips homepage headers).

Code:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Sat, 26 Jun 2004 14:41:34 GMT
Set-Cookie: CFID=29555974;expires=Mon, 19-Jun-2034 14:32:55 GMT;path=/
Set-Cookie: CFTOKEN=20757537;expires=Mon, 19-Jun-2034 14:32:55 GMT;path=/
Set-Cookie: CHANDLE=;expires=Thu, 26-Jun-2003 14:32:55 GMT;path=/
Set-Cookie: CFCLIENT_TEK=;expires=Mon, 19-Jun-2034 14:32:55 GMT;path=/
Set-Cookie: CFGLOBALS=urltoken%3DCFID%23%3D[i](snip)[/i]cfid%3D29555974%23;expires=Mon, 19-Jun-2034 14:32:55 GMT;path=/
[COLOR=red]Content-Type: text/html; charset=UTF-8[/color]

[COLOR=green]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>[/color]

The all important MIME type is sent out by the web server. Anything sent as .html is normally given the content type 'text/html' and text is given 'text/plain'.

A browser would typically render 'text/html' using it's HTML engine, and display 'text/plain' as normal text. By sending an unknown MIME type ('bla/ignore-this') the browser doesn't know how to handle it, so gives you the option of saving it to disk.

Clarkin's post above gives instructions on changing MIME type (otherwise known as 'content disposition') in a Java/JSP server environment.

How you change MIME type depends on which web server you use - but the answer will be in the documentation for your particular server.

<marc> i wonder what will happen if i press this...[ul][li]please tell us if our suggestion has helped[/li][li]need some help? faq581-3339[/li][/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top