« Announcing Show-n-Tell Thursday | Main| Welcome Turtle »

Detecting Browser Plugins, part 2

QuickImage Category Show-n-Tell Thursday

I'm currently posting this off-line, as the internet access in my lodge room is out. The router died yesterday after a power surge, and they won't have a new one installed until tomorrow (probably after I'm on my way home. Grr. Not having access is not at this point a critical or even a major problem, but it is frustrating.

This has been a really busy week, and I haven't been able to devote as much time as I'd hoped to getting this finished before today as I had planned. So, sadly, it isn't complete. But, this being Show-n-Tell Thursday, I'm going to post what I have so far.

Anyway, as I explained earlier, I've been working on some code to detect browser plugins. Frustrating doesn't even begin to describe how this has been. The hard part, however, is pretty much done. I'm not completely finished with it, and I'm most definitely not happy with it, but it is functional. What I have now is some code (a mixture of html, javascript, css, and vbscript) that will detect browser plugins (and has been successfully tested) in Microsoft Internet Explorer 5+, Netscape 4.6+, and Firefox 1.0.7 (I haven't tested in earlier versions of Firefox).

I started out by doing a little research on existing solutions, and the best one I could find was the JavaScript Browser Sniffer by Eric Krok, Andy King, & Michel Plungjan (available at https://www.webreference.com/tools/browser/javascript.html). This is a pretty hefty piece of work, and has been enhanced over the last several years. While their coding style isn't necessarily something I would promote, the simple fact is that it works, and works pretty well. So I decided to use their code as my starting point.

The next thing I looked at was an article on Apple's Developer Connection website. This was a very helpful article, and worthy of reading. I used a small bit of code (7 lines) from the article in my solution. That doesn't mean that the rest of it isn't worthwhile; on the contrary, it is actually a quite elegant piece of work. It just didn't fit in with my needs.

Armed with the aforementioned starting points, I set to work at my task. My requirements (paraphrased from my previous entry) were to write some client-side code that:

  • Did not use ASP, Domino, or CGI
  • Detect and report to the user all of the plugins installed in their browser.
  • Redirect the user to a new page if their browser doesn't have the correct "required" plugins or plugin versions.
  • Code needs to in MSIE 5+, Firefox 1+, and Netscape 4.6+

Whew. That's a tall order. I'll tell you up front that I haven't (and won't be able to) been successful on all points. I still need to write the code that tests to see if the browser meets the requirements, but because of the way I have designed it up to this point, that shouldn't be too big of a problem. My solution doesn't use any "server side" stuff -no ASP, Domino, CGI, Pearl, etc. It does use VBScript, but only for MSIE on Win32 machines. It detects and reports all installed plugins for non-MSIE browsers. It detects and reports specified plugins for MSIE. It doesn't redirect yet, but that is only because I haven't finished the requirements test stuff.

Getting back to the MSIE plugin thing; one of the things I discovered is that you can't detect all plugins installed on Microsoft Internet Explorer. I don't know why, but for some reason the folks in Redmond decided that it wasn't necessary to provide a method to report all plugins when they designed MSIE. You can't event query the browser as to whether or not a specified plugin is installed. Frustrating indeed.

The only way to determine whether or not a specified plugin exists in MSIE is (get ready, because this is insane):

Try to create an object of the specified plugin type. If the code doesn't blow up, the plugin exists.

I know, this design sounds like it was thought up by four drunk monkeys, but seriously, that's how it works. Of course, it being Microsoft, the only way to create the object (that I've found) is by using VBScript. Which means that if you are running MSIE on a Mac, you are simply out of luck. Of course, I can't fathom why any Macintosh users would even consider running MSIE, but aparrently enough of them do to keep the product in production.

I know, you want to see the code. I'll get to that in a minute. But first I want to explore a technique I learned about while trying to solve this problem. I haven't been able to figure out if there is an official term for it (if you know what it is, let me know); so I'm going to call it Run-time Script Insertion. Here is a (modified for brevity) sample of the code I'm using:

Run-time Script Insertion example <script language="javascript" type="text/javascript">
<!--
document.writeln("<scr" + "ipt language=VBscript> ");
document.writeln("\'do a one-time test for a version of VBScript that can handle this code ");
document.writeln("detectableWithVB = False ");
document.writeln("If ScriptEngineMajorVersion >= 2 then ");
document.writeln(" detectableWithVB = True ");
document.writeln("End If ");
document.writeln("</scr" + "ipt> ");
// -->
</script>

What the code is doing is a runtime write (and immediate execution) of VBScript code from within the executing Javascript. Now, this may be old hat to some of you, but for me this is totally new, and therefore very cool. The reason the script tag is broken up ("<scr" + "ipt" and "</scr" + "ipt>") is to stop the browser from interpreting the particular script tag as part of the currently executing Javascript.

I just got a call from the IT folks -the new router is in place! (Woohoo). It's getting late, and I'm pretty tired, so I'm going to close now. I'll explain more details on the code in a forthcoming entry. In the meantime, pull down the sample from the downloads page and check it out. The code is commented, so you should be able to follow it without too much effort.

Sorry for cutting this short, but I'm exhausted and need to hit the sack.

-Devin

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::banghead;:cool::cry::emb::grin::huh::laugh::lips::rolleyes::sniper:;-)

Search

Wowsers! A Tag Cloud!

Links

MiscLinks