PDA

View Full Version : Opera seen as IE?


by350
10-06-2004, 06:46 PM
I'm running a simple Browser/OS sniffer script to determine if a page displays Flash or a static image. I only want the Flash to display in PC/IE. This seems to work fine in all browsers, except for Opera on the PC. Why would the following script still allow Opera to display the Flash file?

<script language="javascript" type="text/javascript">
function browserCheck() {
var isMac = 0;
var isWin = 0;
var isOtherOS = 0;
var isNS = 0;
var isIE = 0;
var isOtherBrowser = 0;

// DETERMINE OS
if (navigator.appVersion.indexOf('Mac') != -1) {isMac = 1;}
else {
if (navigator.appVersion.indexOf('Win') != -1) {isWin = 1;}
else {isOtherOS = 1;}
}

// DETERMINE BROWSER
if (navigator.appName.indexOf('Netscape') != -1) {isNS = 1;}
else {
if (navigator.appName.indexOf('Microsoft Internet Explorer') != -1) {isIE = 1;}
else {isOtherBrowser = 1;}
}
browserVersion = parseInt (navigator.appVersion);

if (isWin && isIE) {
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="740" height="180"><param name="wmode" value="transparent"><param name="movie" value="images/rtg_flash_homepage_740x180.swf"><param name="quality" value="high"><embed src="images/rtg_flash_homepage_740x180.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="740" height="180"></embed></object>');}
else {
document.write('<img src="images/rtg_main_graphic_740x180.jpg" width="740" height="180" border="0" alt="">');
}
}
</script>

RysChwith
10-07-2004, 07:28 AM
Opera can be set to deliberately detect as another browser (pretty much any major one at this point). As far as I know, this is because Microsoft (and a few others) started deliberately hacking their pages to display incorrectly in Opera. Why do you want the Flash to not play in Opera?

Rys

by350
10-07-2004, 09:27 AM
This is for my work intranet and we only support IE. How can I force Opera to not display the flash?

eRad
10-07-2004, 10:16 AM
I design sites for our intranet network also. We only support IE here too.... Which makes my life easy, because i don't have to code for cross-compatibility. But i don't understand the logic behind disabling support for non-IE browsers. If IE is the only browser that will view your site, why not just ignore the rest?

by350
10-07-2004, 12:01 PM
I appreciate your response, but I have a special situation where we only want to display a flash file in IE. Does anyone have a solution for this?

¥åßßå
10-07-2004, 12:15 PM
<!--[if IE]>
<object classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="740" height="180">
<param name="wmode" value="transparent"><param name="movie"
value="images/rtg_flash_homepage_740x180.swf"><param name="quality"
value="high"><embed src="images/rtg_flash_homepage_740x180.swf" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="740"
height="180"></embed></object>
<![endif]-->

Everything between the If & Endif will only be seen by IE every other browser will see it as a comment and ignore it ;)

by350
10-07-2004, 12:19 PM
Cool...thanks! Now is there also a way to add something to my browser/OS sniffer script that will allow me to leave out Opera?

¥åßßå
10-07-2004, 12:26 PM
I think this is the right command :-

if (document.opera){isOpera=1}

But don't quote me on that ! :P

ElectricSheep
10-07-2004, 02:24 PM
I don't like the idea of shutting user agents out but here goes :


Even when Opera is spoofing the word 'Opera' appears in the userAgent string, so you can detect it like this :

if(navigator.userAgent.indexOf("Opera")!=-1)
{
alert("You are Opera");
}
else
{
alert("You are not Opera");
}

So you could make this your last if in the sniffer :

if(navigator.userAgent.indexOf('Opera') != -1) {isOpera = 1;}

Bear in mind some browsers will let users write their own userAgent string.
It is usually better to detect user agent capabilities and deliver code accordingly than try to identify individual browsers.

HTH

by350
10-07-2004, 02:45 PM
Thanks! I'll give this a try.