Solved

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

Posted on 1998-03-23
23
194 Views
Last Modified: 2008-03-17
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 ***

<html>
<head>
<title>testing</title>
</head>
<body>
<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;
            }
      else
            {
            window.event.returnValue = false;
            }
      }
}

//-->
</script>

<BR><BR>
<A
      HREF="http://{address}/{path}/{file.txt}"
      onClick="funcDownload( )"
      >
      Last try
</A>
<BR><BR>
</body>
</html>

*** example, end ***
0
Comment
Question by:tbaum
23 Comments
 
LVL 1

Author Comment

by:tbaum
Comment Utility
Edited text of question
0
 
LVL 1

Author Comment

by:tbaum
Comment Utility
Edited text of question
0
 
LVL 1

Author Comment

by:tbaum
Comment Utility
Edited text of question
0
 
LVL 3

Expert Comment

by:percyn
Comment Utility
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.
0
 

Expert Comment

by:capoeira
Comment Utility
You could use the onMouseDown event handler but that won't work in IE 3 :(
0
 

Expert Comment

by:Richx032098
Comment Utility
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
0
 
LVL 1

Author Comment

by:tbaum
Comment Utility
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).
0
 
LVL 1

Author Comment

by:tbaum
Comment Utility
Richx,

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).
0
 
LVL 6

Expert Comment

by:jpk041897
Comment Utility
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

<HTML>
<HEAD>
<TITLE>A Nationalist JavaScript Page</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
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 -->
</SCRIPT>
</HEAD>
<BODY>
<HR>
Check out the new links to <A HREF="http://home.std.zz"
     onMouseOver="warnthem(this)">Zzland</A>
and its neighbor <A HREF="http://home.xyzzy.xy"
onMouseOver="warnthem(this)">XYville</A>
<HR>
</BODY>
</HTML>

0
 

Expert Comment

by:rajrao
Comment Utility
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 !
0
 
LVL 1

Author Comment

by:tbaum
Comment Utility
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.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 3

Expert Comment

by:percyn
Comment Utility
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.
0
 
LVL 1

Author Comment

by:tbaum
Comment Utility
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?
0
 
LVL 1

Author Comment

by:tbaum
Comment Utility
Still looking for an answer.  Any 'power jocks' out there able to tackle this?  Thanks.
0
 
LVL 3

Expert Comment

by:percyn
Comment Utility
Tbaum,
       I did not say change the mime-types on the client...change them on the SERVER !!!
0
 
LVL 1

Author Comment

by:tbaum
Comment Utility
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!
0
 
LVL 3

Expert Comment

by:percyn
Comment Utility
Ahh,
    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...
0
 
LVL 1

Author Comment

by:tbaum
Comment Utility
I wait with much anticipation!
0
 
LVL 3

Expert Comment

by:percyn
Comment Utility
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. ;-)
0
 
LVL 1

Author Comment

by:tbaum
Comment Utility
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.
0
 
LVL 3

Expert Comment

by:percyn
Comment Utility
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)

Thanks
Percy
0
 
LVL 3

Accepted Solution

by:
percyn earned 800 total points
Comment Utility
Ok,
   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
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\InetInfo\Parameters\MimeMap
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.
Syntax:

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

Note the double comma before the gopher type parameter.
Example:

text/html,htm,,1
image/gif,gif,,5

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.



--------------------------------------------------------------------------------

So,
   You entry would be something like

bogus/file,dnl,,5

   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.
0
 
LVL 1

Author Comment

by:tbaum
Comment Utility
Looks like you win!  The actual 'file' I wound up using is:

<start of file>
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\InetInfo\Parameters\MimeMap]
"application/bogus,XXX,,5:REG_SZ:"=""
"application/bogus,YYY,,5:REG_SZ:"=""
"application/bogus,ZZZ,,5:REG_SZ:"=""
<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!

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now