?
Solved

Cross browser plugin detection

Posted on 1999-09-07
41
Medium Priority
?
425 Views
Last Modified: 2013-11-18
A'ight... this is driving me crazy.  This seems to work in IE4, and Netscrape (althought I haven't tested it on all of them). I put a little indicator where it dies in the code below.  PLEASE HELP!!!!!!


<IMG NAME="test" SRC="x.pdf" HEIGHT=1 WIDTH=1 ALT="">

<SCRIPT LANGUAGE="JavaScript"><!-- // cloak
/* CrossBrowser mime support detection
   (c) Michel Plungjan jav@scripting.demon.nl */

theSuffix = 'pdf';
thePlayer = 'acrobat'

OKText = '<EMB'+'ED SRC="x.pdf" WIDTH="400" HEIGHT="600" name="test" type="pdf" pluginspage="http://www.adobe.com/prodindex/acrobat/readstep.html#reader">';
OKText = '<a href="x.pdf">';
pluginOK = false;
thePlugin = '';

IE = (document.all) ? 1 : 0;
NS = (navigator.appName=='Netscape' && document.images) ? 1 : 0;

if (IE)
   thePlugin = test.mimeType; <--IT SEEMS TO DIE RIGHT HERE.
   if (thePlugin.toLowerCase().indexOf(thePlayer) !=-1) {
   pluginOK = true;
}
if (NS) {
   for (var i=0;i<navigator.mimeTypes.length;i++) {
      if (navigator.mimeTypes[i].suffixes.indexOf(theSuffix) != -1) {
         if (navigator.mimeTypes[i].enabledPlugin) {
            pluginOK = true;
            thePlugin = navigator.mimeTypes[i].enabledPlugin.name;
         }
         break;
      }
   }
}

if (pluginOK) {
   document.write(OKText);
}
else window.location = "http://www.adobe.com/prodindex/acrobat/readstep.html#reader";


// uncloak --></SCRIPT>
0
Comment
Question by:t1pimp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 18
  • 14
  • 7
  • +2
41 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2029344
Dies how??? In what browser on what platform??? In what situation
Have you posted the page exactly as you use it?

Michel
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2029346
perhaps
document.all.test.mimeType
will work better (I apologise if that is so)

Michel
0
 
LVL 3

Expert Comment

by:zhongbing
ID: 2029688
I have check the MS doucment , seems the IMG object dosn't have a mimeType property.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2029816
Of course it does - otherwise I wouldn't have used it...

Run this:
<IMG NAME="test" SRC="x.pdf">
<SCRIPT>
t = ""
for (o in document.all.test) t += o + ':'+ document.all.test[o] + '\n';
alert(t);
</SCRIPT>

on my pc it returns Adobe Acrobat Document
which is what is in the registry under pdf
If it returns PDF File then there is no association installed for that extension.

Could it be that you are not running IE4+ under 32 bit windows?

Michel
0
 

Author Comment

by:t1pimp
ID: 2030235
Yes... gawd, I kept telling myself to remember to put in there that this WORKS under IE4, but on IE5 it dies. So the code works, sorta... but I get an "unspecified error" on the line where I put the  <---  dies here.
0
 
LVL 3

Expert Comment

by:xav
ID: 2030260
Actually, you're both right.

If you access the file as a local file (c:\inetpub\wwwroot\testing\mimeTest.htm) it will work just fine.

However, if you try to access it through the web server (http://localhost/testing/mimeTest.htm) you will get an "Unspecified Error" message, even though it's the same file.

Why?  I have no idea.  But I'll see what I can figure out.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2030284
Oh for &favoriteExpletive; sake
Why is IE such a PITA!!!

Michel
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2030289
If I go to ANY webpage with an image on it and type
javascript:alert(document.images[0].mimeType), I get PaintShop Pro Image
in IE4.01 NT4

So it cannot be that I should think...

Michel

0
 

Author Comment

by:t1pimp
ID: 2030435
AAARRRRRRRGGGGGGGGGG!!  Why is Micro$oft such a pain in the butt!  
0
 
LVL 3

Expert Comment

by:xav
ID: 2030491
OK, I think I may have figured it out.

IE will choke if:

1. it is loaded from a web server (no problems with files accessed locally)
2. you try to access any of the following properties: fileCreatedDate, fileModifiedDate, fileSize, or mimeType

AND

3. the element which you are trying to access is not yet loaded or doesn't exist (in this case, t1pimp probably doesn't (and I didn't) have a file named x.pdf on the server.

If you add a file to your server called x.pdf, Michel's script should work just fine.
0
 

Author Comment

by:t1pimp
ID: 2030938
Ah... I thought you were onto something, I DO have x.pdf on the server.  Could it be that it needs a fully qualified path?   ie http://www.xxx.com/x.pdf?
0
 
LVL 3

Expert Comment

by:xav
ID: 2030977
I'm not sure.  I know that it does have to be wherever the img tag thinks it is (in this case, the same directory as the file), but a fully qualified path should work just as well.

Let me know if this does it, I'm curious.  (I'm still not sure why it doesn't cause errors for local paths.)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2032815
The cool thing about the script was that x.pdf DIDN'T have to exist and therefore
didn't need to be loaded first!

I am disillusioned!

Michel
0
 
LVL 3

Expert Comment

by:xav
ID: 2033581
Yeah, that would be nice.  The real problem is that for some dumb reason, MS added the navigator.mimeTypes array, but never populated it.

Then again, maybe it's just geek humor.  After all, mimes are supposed to be silent.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2033599
LOL!
and of course the plugins array is also plugged shut :(
Michel
0
 

Author Comment

by:t1pimp
ID: 2034631
Nope, even with the fully qualified path it doesn't work. This stinks...  so if the mimeType array is not populated, is there any other way to find out if a plugin is there?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2034943
Nope, sorry... I had a script that creates an activeX object of the specified type but it gives major script errors in case the plugin is NOT there...

Michel
0
 
LVL 3

Expert Comment

by:xav
ID: 2037016
td1pimp,

Is the page you're working on somewhere where we can get to it?  Putting in the x.pdf file seemed to work for me, so I'm not sure where else to look without seeing your page in action.
0
 

Author Comment

by:t1pimp
ID: 2037783
0
 

Author Comment

by:t1pimp
ID: 2037842
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2039365
I think I see your problem !!! Your x.pdf exists!!! and takes forever to donwload so the scrip is already trying the mimetype on a 343K image before it is there...

Use "x.pdf" and make sure that does NOT exist. We do not want to load a pdf, only check if pdf is supported!

Michel
0
 

Author Comment

by:t1pimp
ID: 2039545
Right, but what good does that do me if it DOES exist?  I mean, I need it to exist, hence the reason for checking to see if it's there.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2040685
You miss the point. You need to test the browser support for pdf, NOT the existense of a file!!! The test uses the EXTENSION of a non-existent file to test this. It even uses the IMG tag which will be useless for your actual pdf file which needs to be either embedded or loaded into a window/frame.
So your action is: Test if there is any point in loading the pdf file, using my script and a dummy pdf filename, and if so, load the real file!

Michel
0
 
LVL 3

Expert Comment

by:xav
ID: 2042185
Michel's right, you're not really checking anything about the x.pdf file, you're just using the src="x.pdf" as bait to sucker the mime support out of the browser.  For some reason, it won't work for me unless there is an x.pdf file on the server, however, I had just 1 byte text file, and renamed it x.pdf, so it loaded immediately.
0
 

Author Comment

by:t1pimp
ID: 2043813
I see...  you guys are awesome!  I can't wait to get to work and try this out.  Thanx so much for your help!!!!
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2044341
I hope it works for you...

Michel
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2081448
So did it work???

Michel
0
 

Author Comment

by:t1pimp
ID: 2082732
No, haven't gotten to spend much time with it tho... other projects keep pulling me away. And I REALLY appreciate you following up, it's amazing you've spent this much time helping out!  I REALLY appreciate it.

I tried it with IE5 with no luck. I'll try it with IE4, but the other way worked in IE4 too. So I don't know what good it would do?

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2082747
What happened in IE5??? Did you have a dummy pdf file stored on the server and is the server set up to handle pdf???

What other way worked in IE4?

I really like to know because I have written this code and I want it to work since it seems to be one of the VERY few ways to detect a plugin in IE.

I plan to use it on
http://ep.espacenet.com/espacenet/ep/en/e_net.htm

Michel
0
 

Author Comment

by:t1pimp
ID: 2085422
Ok... per what we had at the first posting it wouldn't work.  I went back and check Michels scripts that I started with, before tinkering, and then changed a couple of things.  Here's what I ended up with, and it appears to work in both IE5, Netscrape 3.04 & 4.6.


<html>
<head>
      <title>PDF Plugin Script</title>
</head>

<body>

<IMG NAME="testimage" SRC="x.pdf" HEIGHT=1 WIDTH=1 ALT="">

<SCRIPT LANGUAGE="JavaScript">
<!-- // cloak
/* CrossBrowser mime support detection
   (c) Michel Plungjan jav@scripting.demon.nl */

theSuffix = 'pdf';
thePlayer = 'acrobat'

OKText = '<EMB'+'ED SRC="y.pdf" WIDTH="100%" HEIGHT="100%">';
notOKText = 'Here we could have had a PDF file';
pluginOK = false;
thePlugin = '';

IE = (document.all) ? 1 : 0;
NS = (navigator.appName=='Netscape' && document.images) ? 1 : 0;

if (IE)
   thePlugin = testimage.mimeType;
   if (thePlugin.toLowerCase().indexOf(thePlayer) !=-1) {
   pluginOK = true;
}
if (NS) {
   for (var i=0;i<navigator.mimeTypes.length;i++) {
      if (navigator.mimeTypes[i].suffixes.indexOf(theSuffix) != -1) {
         if (navigator.mimeTypes[i].enabledPlugin) {
            pluginOK = true;
            thePlugin = navigator.mimeTypes[i].enabledPlugin.name;
         }
         break;
      }
   }
}

if (pluginOK) {
   document.write(OKText);
}
else window.location = "http://www.adobe.com/prodindex/acrobat/readstep.html#reader";


// uncloak --></SCRIPT>


</body>
</html>
0
 

Author Comment

by:t1pimp
ID: 2085426
oh... i forgot to mention.  I also had to have a 1k file ON the server to get this to work.  X.PDF is just a text file with 3 characters in it renamed to a pdf extension.  Y.PDF is the actual pdf that I wanted loaded.  


The only visible error, is that Netscape 3.04 shows a broken box where the x.pdf was supposed to be.
0
 

Author Comment

by:t1pimp
ID: 2085510
Code problem:
The way it is currently set up it WILL launch the PDF in all browsers, but it will NOT launch the Acrobat reader controls.  To get it to do this... use the following code:

<html>
<head>
      <title>PDF Plugin Script</title>
</head>

<body>

<!-- use a bogus 1k text file renamed to a pdf extension to coax IE into giving us the MIME type availability. -->
<IMG NAME="testimage" SRC="x.pdf" HEIGHT=1 WIDTH=1 ALT="">

<SCRIPT LANGUAGE="JavaScript">
<!-- // cloak
/* CrossBrowser mime support detection
   (c) Michel Plungjan jav@scripting.demon.nl
   Modified to include PDF controls by Paul Spoerry pspoerry@navisys.com */

// plugin information
theSuffix = 'pdf';
thePlayer = 'acrobat'

pluginOK = false;
thePlugin = '';

IE = (document.all) ? 1 : 0;
NS = (navigator.appName=='Netscape' && document.images) ? 1 : 0;

if (IE)
   thePlugin = testimage.mimeType;
   if (thePlugin.toLowerCase().indexOf(thePlayer) !=-1) {
   pluginOK = true;
}
if (NS) {
   for (var i=0;i<navigator.mimeTypes.length;i++) {
      if (navigator.mimeTypes[i].suffixes.indexOf(theSuffix) != -1) {
         if (navigator.mimeTypes[i].enabledPlugin) {
            pluginOK = true;
            thePlugin = navigator.mimeTypes[i].enabledPlugin.name;
         }
         break;
      }
   }
}

// if plugin is detected, write out REAL information for PDF to launch
if (pluginOK) {
    window.location = "y.pdf";
}
// if plugin is NOT detected then send them to the Adobe Reader download site.
else window.location = "http://www.adobe.com/prodindex/acrobat/readstep.html#reader";


// uncloak --></SCRIPT>


</body>
</html>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2085840
Either do this before the test

if (document.images) document.write('<IMG NAME="testimage" SRC="x.pdf" HEIGHT=1 WIDTH=1 ALT="">');

or do this little trick I have just considered but not tested:



<SCRIPT LANGUAGE="JavaScript"><!-- // cloak
/* CrossBrowser mime support detection
          (c) Michel Plungjan jav@scripting.demon.nl
          Modified to include PDF controls by Paul Spoerry pspoerry@navisys.com */

if (document.all) {
   testImage = new Image(); testImage.src = 'x.pdf';
}

Adios broken image...

Michel
}
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2085845
PS: What exactly didn't work in IE5???
0
 

Author Comment

by:t1pimp
ID: 2089469
I don't remember exactly... it's been a couple of weeks since I played with it when it didn't work.  If I recall, it wouldn't detect the plugin.  But it's likely that it was a code error on my part. I dunno. You could always cut and paste the original code I posted up above and test it... it should bomb on IE5.  Also... just a note, the latest code posting I did eliminates the broken image as well, because it forwards it with the window.location and opens the pdf as a new page.

Thanx again for all your help. This took a LONG time to resolve... wish IE wasn't such a pud!

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2090311
So who gets the points?

Michel
0
 
LVL 3

Expert Comment

by:xav
ID: 2090700
I vote for Michel.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2090837
Me too ;-)
0
 

Author Comment

by:t1pimp
ID: 2092169
Me too!  
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 800 total points
ID: 2094000
Thanks ;-)

Michel
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6869636
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

719 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