Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 10th, 2006, 07:46 AM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Sean1989
Default Browser Detect & Display DIV Script

Hey all i got a bit of script that i can't seem to get to work. It is suppose to detect IE6, then display a message at the top of the page. Can you tell me whats wrong with it.

<HEAD>
<SCRIPT language="JavaScript">
<!--
var browserName=navigator.appName;
var browserVer=parseInt(navigator.appVersion);
if (browserName=="Microsoft Internet Explorer" && browserVer=6)
  version="6";
else
  version="7";

if (version=="6")
  document.getElementById("IEMessage").style.display = "block";
//-->
</SCRIPT>
</HEAD>
<body>
<div id="IEMessage" style="display: none; width: 100%; background: #FFFFFF; padding: 5px;">Message Here</div>
</body>

Thanks alot

Sean

 
Old August 31st, 2006, 07:36 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Sean!!
two errors in your code
1> if (browserName=="Microsoft Internet Explorer" && browserVer=6)
solution-
if (browserName=="Microsoft Internet Explorer" && browserVer==6)
2> document.getElementById("IEMessage").style.display = "block";
reason-->at the time of code executing ,no element will be found with Id as
IEMessage since ,it will execute first before actual ID will be loaded on the browser
solution ->you can use it onload event of the body ,or atleast after IEMessage "div" will loaded into the browser.
Note-Always be careful with parseInt ,use parseInt(number,radix)
Reason- e.g parseInt("08") will give 0 so use parseInt("08",10) for decimal

detail code is below-->

<HEAD>
<SCRIPT language="JavaScript">
<!--
function callme()
{

var browserName=navigator.appName;

var browserVer=parseInt(navigator.appVersion);

if (browserName=="Microsoft Internet Explorer" && browserVer==6)
   version="6";
else
  version="7";


if (version=="6")
  document.getElementById("IEMessage").style.display = "block";

}
//-->
</SCRIPT>
</HEAD>
<body onload="callme()">
<div id="IEMessage" style="display: none; width: 100%; background: #FFFFFF; padding: 5px;">Message Here</div>
</body>

Hope this will help you

Cheers :)

vinod
 
Old September 1st, 2006, 08:18 AM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Sean1989
Default

Thanks for the help ;)






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to detect in asp.net browser window close connect2sandep ASP.NET 1.0 and 1.1 Professional 1 October 31st, 2005 05:01 AM
Desperately Need Help with Loop & Display Script pupadu Classic ASP Basics 2 March 28th, 2005 07:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.