PDA

View Full Version : Trying to fix a if brower='IE'...



NineTwoZero
05-07-2007, 08:26 AM
var IE = 'Microsoft Internet Explorer'
var FF = 'Netscape'
var browser = '+navigator.appName+'

if (browser =='IE')
{

alert("this page does not support internet explorer. You will be redirected to another page with more information.');

window.location.replace("ieusers.html");

}trying to fix so an alertbox pops up and then when u click the OK, u get redirected to ieusers.html. :cool:

how come my homemade scripts never work? :(

tech_support
05-07-2007, 09:00 AM
Try this:


<!--[if IE]>
<meta http-equiv="refresh" content="3;url=ieusers.html">
<![endif]-->

It'll redirect to the IE page in 3 seconds and requires no JavaScript.
You need to put this in the <head> section with the other <meta...> tags.

mwinter
05-07-2007, 10:49 AM
var browser = '+navigator.appName+'

This statement declares a variable, browser, initialised with a string literal. This literal contains the nineteen characters, "+navigator.appName+". What you're trying to do is assign the value of a property to the variable, which should be written:



var browser = navigator.appName;

That said, the technique you're trying to employ - browser detection - is flawed and unreliable. Don't do it.



alert("this page does not support internet explorer. ...

Then that page needs to be fixed. Creating two or more separate documents for different groups of visitors just adds unnecessary work for you.

The use of a dialogue box is questionable: why should the user need to know that you want to use two different documents? Implementation details should be kept from users. At best, the user won't care, at worst, they won't understand what's happening, and will become confused thinking that something's wrong.

Mike

NineTwoZero
05-07-2007, 02:49 PM
im still polishing the site but feel free to have a peek. http://920.ninetwozero.com
doesnt work in IE (as far as i know.)

This statement declares a variable, browser, initialised with a string literal. This literal contains the nineteen characters, "+navigator.appName+". What you're trying to do is assign the value of a property to the variable, which should be written:



var browser = navigator.appName;

That said, the technique you're trying to employ - browser detection - is flawed and unreliable. Don't do it.


Then that page needs to be fixed. Creating two or more separate documents for different groups of visitors just adds unnecessary work for you.

The use of a dialogue box is questionable: why should the user need to know that you want to use two different documents? Implementation details should be kept from users. At best, the user won't care, at worst, they won't understand what's happening, and will become confused thinking that something's wrong.

Mike
i dont have a clue why it aint workin in ie so im was gonna redirect to ieusers.html where u can go straight to the forum or getfirefox.com lol


Try this:


<!--[if IE]>
<meta http-equiv="refresh" content="3;url=ieusers.html">
<![endif]-->

It'll redirect to the IE page in 3 seconds and requires no JavaScript.
You need to put this in the <head> section with the other <meta...> tags.
aight will test it. thanks m8. =D

mwinter
05-07-2007, 03:43 PM
http://920.ninetwozero.com
doesnt work in IE (as far as i know.)

It doesn't render anything in IE, and probably other browsers too, because you're trying to use XML-like syntax in a HTML document. This is why I constantly say that unless authors understand XML (and XHTML) throughly, they should not attempt to use it on the Web. It only leads to trouble.

Mike

jscheuer1
05-07-2007, 04:12 PM
Yeah, Mike's right. This is wrong:


<script src="super.js" type="text/javascript"/>
<!--[if IE]>
<meta http-equiv="refresh" content="0;url=ieusers.html">
<![endif]-->
<script src="menu.js" type="text/javascript"/>

It should be:


<script src="super.js" type="text/javascript"></script>
<script src="menu.js" type="text/javascript"></script>

Then you wouldn't even need the redirect.

From the point of view of proper coding, there are other problems. But that change will allow the page to render fine in IE.

You may not want to code to spec. But, at least don't use self closing tags for tags that normally have a separate closing tag.

NineTwoZero
05-07-2007, 04:12 PM
It doesn't render anything in IE, and probably other browsers too, because you're trying to use XML-like syntax in a HTML document. This is why I constantly say that unless authors understand XML (and XHTML) throughly, they should not attempt to use it on the Web. It only leads to trouble.

Mike

so basiclly its coz of my doctype?

jscheuer1
05-07-2007, 04:16 PM
No, it is your misuse of self closing tags for your script tags. See my previous post in this thread. The DOCTYPE isn't proper for what you are doing, no. But IE will overlook that, not the invalid (for HTML - all that IE understands) tags though.

NineTwoZero
05-07-2007, 04:34 PM
No, it is your misuse of self closing tags for your script tags. See my previous post in this thread. The DOCTYPE isn't proper for what you are doing, no. But IE will overlook that, not the invalid (for HTML - all that IE understands) tags though.

alright. thx for the help :]