PDA

View Full Version : Browser detection help



JEES
08-22-2008, 04:30 PM
Hello, i am totally new to javascript and i want to know how to get this thing done in java, the question is how to write a piece of code depending on what browser is the client using like:

if IE6{
code A
}
else(){
code B
}

then in the html corrosponding div there's document.write()

Thanks in advance

boogyman
08-22-2008, 05:19 PM
what are you trying to perform that would require different browsers?

technically speaking it is generally advisable to display the same thing to all browsers.

JEES
08-22-2008, 06:33 PM
thanks for your reply boogyman, well technically i used a "modified" html code to embed flash without affecting the XHTML standards, the problem is when add the code for getting rid of "click to activate" thingy it still work in FF and Opera, but not in IE.. it makes IE crashes.

So, since the part of the original flash embeding code which is not XTHML standard is this part :
<embed>...</embed>

so i can still use the normal flash code when the browser is IE, and if not IE, the code will be the modified one.

Thanks

Twey
08-22-2008, 10:44 PM
The usual method of embedding Flash is one popularised under the name Flash Satay (http://www.alistapart.com/articles/flashsatay). However, it's very likely that you shouldn't be using XHTML at all (and that in fact you aren't right now, even if you think you are) — IE does not support it. Try reading http://www.webdevout.net/articles/beware-of-xhtml.

JEES
08-22-2008, 11:13 PM
[QUOTE=Twey;158559]The usual method of embedding Flash is one popularised under the name Flash Satay (http://www.alistapart.com/articles/flashsatay). QUOTE]

First of all thank you for answering.. well it's something like Flash Satay, it just uses a faked gif instead of a swf.. let me show you the code:

<object type="application/x-shockwave-flash" data="Movie1.swf" width="760" height="350">
<param name="movie" value="Movie1.swf" />
<param name="wmode" value="transparent" />
<param name="menu" value="false" />
<img src="banner.gif" width="760" height="250" />
</object>

it works very well in all browsers (Including IE), the problem is when i add the js code that will remove the dotted rectangle (click to activate), IE crashes, while it works fine in FF, Safari and Opera.

One more thing.. it may be true that IE doesn't support XHTML, However it's validated as XHTML and LOOKS the way i want it to look like in IE as well.

Thanks

Twey
08-23-2008, 12:22 AM
One more thing.. it may be true that IE doesn't support XHTML, However it's validated as XHTML and LOOKS the way i want it to look like in IE as well.It's not really valid. The validator thinks it's valid, but the validator determines whether to use HTML or XHTML by the DOCTYPE provided. Browsers don't: they judge by the Content-Type header that your server sends. If you can view the page in IE, that means that that Content-Type header is text/html.

In other words, you're actually serving broken HTML to the clients that matter. There is no advantage and a fair few disadvantages as compared to serving correct, strict HTML.