Cross browser plugin detection

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>
t1pimpAsked:
Who is Participating?
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
Thanks ;-)

Michel
0
 
Michel PlungjanIT ExpertCommented:
Dies how??? In what browser on what platform??? In what situation
Have you posted the page exactly as you use it?

Michel
0
 
Michel PlungjanIT ExpertCommented:
perhaps
document.all.test.mimeType
will work better (I apologise if that is so)

Michel
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
zhongbingCommented:
I have check the MS doucment , seems the IMG object dosn't have a mimeType property.
0
 
Michel PlungjanIT ExpertCommented:
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
 
t1pimpAuthor Commented:
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
 
xavCommented:
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
 
Michel PlungjanIT ExpertCommented:
Oh for &favoriteExpletive; sake
Why is IE such a PITA!!!

Michel
0
 
Michel PlungjanIT ExpertCommented:
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
 
t1pimpAuthor Commented:
AAARRRRRRRGGGGGGGGGG!!  Why is Micro$oft such a pain in the butt!  
0
 
xavCommented:
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
 
t1pimpAuthor Commented:
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
 
xavCommented:
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
 
Michel PlungjanIT ExpertCommented:
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
 
xavCommented:
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
 
Michel PlungjanIT ExpertCommented:
LOL!
and of course the plugins array is also plugged shut :(
Michel
0
 
t1pimpAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
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
 
xavCommented:
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
 
t1pimpAuthor Commented:
0
 
t1pimpAuthor Commented:
0
 
Michel PlungjanIT ExpertCommented:
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
 
t1pimpAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
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
 
xavCommented:
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
 
t1pimpAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
I hope it works for you...

Michel
0
 
Michel PlungjanIT ExpertCommented:
So did it work???

Michel
0
 
t1pimpAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
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
 
t1pimpAuthor Commented:
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
 
t1pimpAuthor Commented:
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
 
t1pimpAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
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
 
Michel PlungjanIT ExpertCommented:
PS: What exactly didn't work in IE5???
0
 
t1pimpAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
So who gets the points?

Michel
0
 
xavCommented:
I vote for Michel.
0
 
Michel PlungjanIT ExpertCommented:
Me too ;-)
0
 
t1pimpAuthor Commented:
Me too!  
0
 
MoondancerCommented:
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
All Courses

From novice to tech pro — start learning today.