View Full Version : Browser detection problem

07-16-2009, 04:42 PM
I've got a pop-up WMP that works ok in IE but my detection code isn't helping me with the other browsers. Any suggestions are appreciated.

This is my JS file:

function PlayerOpen() {

var visitorOS=0
var UniqueID=0
var objTypeTag=0
PlayWin = window.open('',UniqueID,'width=320,height=190,top=0' + ',left=0,resizable=0,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0,personalbar= 0');

var isWin = navigator.userAgent.toLowerCase().indexOf("windows") != -1;
if (isWin) { // Use MIME type application/x-mplayer2
else { // Use MIME type audio/mpeg, audio/x-wav, etc.

var objTypeTag = "application/x-mplayer2"; // MIME type for non-IE browsers on Windows
if (visitorOS != "Windows") { objTypeTag = "audio/x-ms-wma"}; // MIME type for Linux & Mac
var winContent = "<HTML><HEAD><TITLE> Sturtevant Technical Services </TITLE></HEAD><BODY bgcolor='#FF9900'>";
winContent += "<B style='font-size:14px;font-family:Verdana,sans-serif;line-height:1.5'><DIV ALIGN='CENTER'+";
winContent += ">Sturtevant Technical Services</DIV></B>";
winContent += "<OBJECT id='mediaPlayer' width='300' height='69'";
winContent += "classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'";
winContent += "codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'";
winContent += "standby='Loading Microsoft Windows Media Player components...' type='objTypeTag'>";
winContent += "<param name='fileName' value='http://www.sturtevantfan.com/Audio/sturtevantaudio.asx'>";
winContent += "<param name='animationatStart' value='1'>";
winContent += "<param name='ShowStatusBar' value='1'>";
winContent += "<param name='transparentatStart' value='1'>";
winContent += "<param name='autoStart' value='1'>";
winContent += "<param name='showControls' value='1'>";
winContent += "<param name='loop' value='0'>";
winContent += "<EMBED type='objTypeTag'>";
winContent += "pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'";
winContent += "id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1'";
winContent += "bgcolor='darkblue' showcontrols='true' showtracker='-1'";
winContent += "showdisplay='0' showstatusbar='1' videoborder3d='-1' width='300' height='69'";
winContent += "src='http://www.sturtevantfan.com/Audio/sturtevantaudio.asx' autostart='true' designtimesp='5311' loop='false'>";
winContent += "</EMBED>";
winContent += "</OBJECT>";
winContent += "</td></tr>";
winContent += "<FORM><DIV align='center'><INPUT type='button' value='Close this window'+";
winContent += "onClick='javascript:window.close();'></DIV></FORM>";
winContent += "</BODY></HTML>";

08-07-2009, 02:13 PM
Oh(( I've got the same problem(

08-07-2009, 02:41 PM
Shouldn't this be in the Javascript section.

08-07-2009, 07:25 PM
This should be in the garbage can (dustbin). If you can’t write code that works in all browsers then you shouldn’t develop websites at all.

JavaScript browser detection things are making me aggressive because that’s the most amateurish approach there is (and looking at the code above makes me even more aggressive because I can’t stand the crap that circulates on the internet). I’m only gonna give you this much of a hint: Check for the support of certain methods or objects, not for browsers or operating systems (even worse: with JavaScript, which can be disabled or not available at all in the first place).

Ideally you would provide a non-proprietary file format that all browsers support or check for the support of a certain format or MIME type or whatever and provide the media based on that support. Likewise you’d use some variation of the Flash Satay (http://www.alistapart.com/articles/byebyeembed/) to embed external media and scrap the old embed kind of way. Alternatively you could use Flash which is supported by and installed in many browsers in many OSs.