Hi there.
I have written a small code that will call an alert box if it detects Internet Explorer. Trouble is, it don't work 
Here is my code... Can someone please point me in the right direction?
<script type="text/javascript">
var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
var answer = confirm("Browser Incompatible - Firefox Needed")
if (answer){
alert("You won't be disappointed!'")
window.location = "http://www.mozilla-europe.org/en/products/firefox/";
}
else{
alert("Some elements of this Website will not be displayed correctly.");
}
</script>







pr0gr4mm3r posted this at 03:47—30th April 2008.
He has: 470 posts
Joined: Sep 2006
It's missing a closing brace and some semicolons. I copied in a revision that works under Firefox. I replaced if (browserName=="Microsoft Internet Explorer") to if (true) and it showed the appropriate alert on my browser. I don't have IE to fully test it though.
<script type="text/javascript">var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
var answer = confirm("Browser Incompatible - Firefox Needed");
if (answer)
{
alert("You won't be disappointed!'");
window.location = "http://www.mozilla-europe.org/en/products/firefox/";
}
else
{
alert("Some elements of this Website will not be displayed correctly.");
}
}
</script>
Reece S posted this at 12:01—30th April 2008.
He has: 165 posts
Joined: Oct 2007
Aha! This works great. Thank you so much.
webwiz posted this at 16:38—30th April 2008.
He has: 280 posts
Joined: May 2007
Yes - that will work most of the time. But be aware that some browsers, such as Opera, can fake the navigator string. I do it so that I can get into my bank account, which normally bans Opera.
You may be better off using Microsoft's Conditional Comments in your script.
Cordially, David
--
"Old web developers don't die, they degrade gracefully..."