Looking for a way to trap left-clicks for I.E. browsers.

I have a WEB app that is made up of an HTML page that is a frame only and other HTML pages are loaded into this frame.  One of these HTML pages (that is loaded into the frame) allows the user to download a text file.  Under Netscape browsers, the user 'left-clicks' and the file is downloaded.  Under I.E. browsers, instead of downloading the file, it is displayed in frame, replacing the HTML page that contained the link.

What I want to do (and have tried to do unsuccessfully) is trap the 'left-click' when the browser is I.E. and inform the user that to successfully download the file, they need to 'right-click' and select 'Save Target As' from the floating menu.  I have actually created something like that, that works for I.E. 4.0 (always) and I.E. 3.02 when the HTML page is not running in a frame.  I need a solution that works all of the time.  I know about setting up defaults for file extentions and that will not work in this case.  The file extentions will vary but they will always be text files.

I have included what I have done so far.  As part of the answer, I would like a working example that consists of a frame HTML page that loads the download HTML page and correctly allows the Netscape 'left-click' to work and traps the I.E. 'left-clicks' for the 4.X and 3.X versions of the browsers.

*** example, start ***

<script language = "JavaScript">

function funcDownload( )
sBrowserName = navigator.appName;
nBrowserVersion = parseInt( navigator.appVersion);

if ( sBrowserName == "Microsoft Internet Explorer" )
      alert( "\nRemember:\n\nTo download a file you need to 'right-click' and\nchoose 'Save Target As' not 'left-click'." );

      if ( nBrowserVersion < 4 )
            self.location = this.document.location;
            window.event.returnValue = false;


      onClick="funcDownload( )"
      Last try

*** example, end ***
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tbaumAuthor Commented:
Edited text of question
tbaumAuthor Commented:
Edited text of question
tbaumAuthor Commented:
Edited text of question
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Do you have to call the file "file.txt" ? You can change the extention of the file to something like .dnl and change the mime-type settings on the server to send a mime type of "application/unknown" for that extension.

That way anytime the user clicks on a file with a .dnl ext, the "Save As" bax will appear.
You could use the onMouseDown event handler but that won't work in IE 3 :(
try changing your link from "http:\\" to "ftp:\\". This seems too simple of an answer so I must not understand the question fully but, I hope this helps anyway.   -Richx
tbaumAuthor Commented:
percyn, I do not have the option of doing that.  I do not have control over the client's browser settings.  Also, the extension is not actually 'txt'.  All of the files are text files but the extensions are like 'OFC', 'DIF' & 'QCF'.  When you left-click on the link, I.E sees that they are really text files (regardless of the extension) and displays them in the frame instead of prompting to save as a file (like Netscape does).
tbaumAuthor Commented:

Nice try!  But when I tried that (using 'ftp' instead of 'http') I.E. 4.0 still desplayed the contents of the file in the frame instead of prompting my for a file name (to save to disk).
The idea i'm proposing would not detect the right click (or distinguish it from a middle button), but it will substitute correctly for that functionality.

Have you considered using the MouseOver event?

Set up a flag to a default of false, if the mouse is placed over a given file link (the ones that are giving you grief), allow it to set the flag, if the mouse goes over any other link reset the flag.

Once the user hits the left click, you can check the value of the flag and determine wether to laod or display the message.

The only potential problem would be false positives, i.e.: the mouse went over a file link and then hit the mouse button somwhere you have not placed code to reset the flag. But that kind of error should surface in testing and will generaly only appear in immage maps.

Although the following code does not do what you ask, it should give you the general feel of the use of

<TITLE>A Nationalist JavaScript Page</TITLE>
function warnthem( lnk ) {               // mouseOver event handler
     var theirhost = lnk.hostname;          // 2; get hostname of link
     var domain = "", lastdot = 0, len = 0;
     len = theirhost.length;          // 4; string length of hostname
     lastdot = theirhost.lastIndexOf(".");     // 5; find last dot
     domain = theirhost.substring(lastdot+1, len); // 6; last part of hostname
     if ( domain == "zz" ) {          // 7; warn about country "zz"
          alert("Country zz only has 1200 baud modems");
<!-- end script -->
Check out the new links to <A HREF="http://home.std.zz"
and its neighbor <A HREF="http://home.xyzzy.xy"

One not so elegant option is to ZIP the file and make it
self extracting with an EXE extention !

But, the file size will bloat. A text file of  2 KB increases to
about 27 KB using Winzip 6.3.

Just in case nothing else works !
tbaumAuthor Commented:
That is not really acceptable.  First, there would always be a pop-up when the user moused over the link (not great) and I would not be preventing the offending action.  Just warning against it.  I NEED to trap the left-click and prevent the user from getting it wrong!  There is no way to do this that will work under I.E. 3x?  The complete answer has to work with Netscape browsers, I.E. 3.X and I.E. 4.X but that does not mean that the complete answer is version nutral.  As in the base example I submitted, there can be version and vender checking.

No one else has ever had this problem before?  What do you say guys/gals.  Give it another shot?  Thanks.
I think you are going about the wrong way, trying to solve this problem. The thing that makes NS save the question is the mime-type that is sent to it. IE is interpreting the mime-type as a text file and is trying to display it.

What you REALLY want is to have the server tell the browser what mime-type the file (extension) is and then have the browser act appropriately.

Setting the correct mime-type depends on the server. In IIS 4.0, you can go under HTTP headers and add a new mime-type. In Netscape server, there is a mime.types file. Say the file you want to download has an extension of .dnl . Then your mime-type associated with this file would be bogus/dnl .

I had the same problem with .h files, which IE interpreted as text and this is how I solved it.
tbaumAuthor Commented:
I am using IIS 4.0 and I can not locate this area of which you speak.  Can you walk me through the program and screens to access this option?
tbaumAuthor Commented:
Still looking for an answer.  Any 'power jocks' out there able to tackle this?  Thanks.
       I did not say change the mime-types on the client...change them on the SERVER !!!
tbaumAuthor Commented:
I understand that.  I have tried looking for where the mime type can be changed, on the server, in both IIS 3.0 (from the Internet Service Manager, properties) and in the Internet Information Server Setup program and can not find it (sorry that I said 4.0 earlier).  If you could walk me through accessing those options, I would be ever so grateful!
    It is much easier in IIS 4.0, because there is a way to change it from the MMC, but in IIS 3.0, it is burried in the reistry somewhere. I will have to dig it up...
tbaumAuthor Commented:
I wait with much anticipation!
Since you are in a hurry and I don't have an IIS 3.0 machine in front of me, check out the article at http://support.microsoft.com/support/kb/articles/q165/0/24.asp , which shows you how to add a mime-type to IIS. Now just follow the example, but use application/bogus as your mime-type.

Let me know how it works (it works great in IIS 4.0) and then I will submit it as the answer. ;-)
tbaumAuthor Commented:
I will need you to send me a copy of the actual reg file to use to apply that mime type to the registry.  I attempted to follow the article you mentioned and just finished rebuilding the system.  If you could export your registry entries and post the part for applying the mime types or the actual update reg file, would be most appreciated.  Thanks.
Tell you what...it might be faster for you to email me the registry key at percy@percy.com, since I cannot seem to find an IIS 3.0 machine (upgraded all to IIS 4.0)

   This is straight from an IIS 3.0 helpfile ....

Server MIME Mapping
If your server provides files that are in multiple formats, you must configure your server’s Multiple Internet Mail Extensions (MIME) mapping to ensure your server maps the file type correctly when returning the file to remote browsers. If MIME mapping on the server is not set up for a specific file type, browsers may not be able to retrieve the file. More than 100 MIME mappings are installed by default.

To configure additional MIME mappings
1. Start the Registry Editor (Regedt32.exe) and open
Note that each MIME type is a REG_SZ with the type of information as the name of the value with an empty value.

2. Add the value for the MIME mapping needed on your server by using the following syntax.

<mime type>,<filename extension>,,<gopher type>

Note the double comma before the gopher type parameter.


In this example, when clients ask the Web server for a file that ends in the extension .gif, the MIME type returned to the client would be image/gif.

The default entry with the file-name extension specified as an asterisk (*) is the default MIME type used when a MIME mapping does not exist. For example, to handle a request for the file Current.vgr when the the file-name extension .vgr is not mapped to a MIME type, the server will use the MIME type specified for the asterisk extension, which is the type used for binary data. Usually, this will cause browsers to save the file to disk.


   You entry would be something like


   Keep in mind that if this is a text file, IE 4.0 seems to have a bug in it, whereby it will try to display the text file instead of trying to download it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tbaumAuthor Commented:
Looks like you win!  The actual 'file' I wound up using is:

<start of file>
<end of file>

I named this file "mime.reg" and double-clicked on it to loaded it (on the web server).  It seems to be working great.  It also seems to be working with IE 4 and IE 3x.  It is not the answer I was origionally looking for but it does solve the problem I wanted solved.  And as always, that is the point.  Now when I left-click on a link that contains a file with one of these extensions, the file is downloaded.  Thank you to everyone that sent me answers.  This is a great resource!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.