FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Javascript: Check browser + show item.

 


James007
Hi all,

I want to make an element visible, when people using Internet Explorer 6 visit my page. I want this element to be called by ID.

Something like:
If the browser = IE6, then element with ID "blah" gets display: block;

Can someone help me please? Smile

James Smile
LukeakaDanish
Code:


if (navigator.appName == "Microsoft Internet Explorer 6") {
document.getElementById('blah').style.display = 'block';
}



Dunno if that will work...try it out...it can certainly identify IE if you remove the six...
James007
Uhm... I am a complete noob... where should I put it? In the head-section? In the body? Which tags? Embarassed
LukeakaDanish
Ok...sorry...your admin rank made me respect your skillz...Very Happy

Code:


<script language="javascript" type="text/javascript">

<!--

if (navigator.appName == "Microsoft Internet Explorer 6") {
document.getElementById('blah').style.display = 'block';
}

-->

</script>




just paste it inside the <head> section

If you want a general IE function - remove the 6 from the end of the "appName"

change "blah" to the ID of your object
LukeakaDanish
Just thought of something...might be better of using visibility: hidden; instead of display: none;

the script code would then look like this:

Code:


<script language="javascript" type="text/javascript">

<!--

if (navigator.appName == "Microsoft Internet Explorer 6") {
document.getElementById('blah').style.visibility = 'visible';
}

-->

</script>

James007
I respect your skills too, and you're not an admin. (neighter am I actually)

I'll try your code a.s.a.p. (tomorrow).

Thank you!

James007
James007
Well... I have a div with id "warning", but that div does not disappear in Firefox when I use your code.

I tried another code from internet (here)

I adapted it slightly so I could make the div visible for all Internet Explorer 6 (or lower) users.

Code:
<SCRIPT language="JavaScript" type="text/javascript">
<!--
var browserName=navigator.appName;
var browserVer=parseInt(navigator.appVersion);
if ((browserName=="Microsoft Internet Explorer" && browserVer<=6))
  version="n3";
else
  version="n2";

if (version=="n3")
  document.getElementById('warning').style.display = 'block';
else
  document.getElementById('warning').style.display = 'none';
//-->
</SCRIPT>


But STILL the div shows up in Firefox, so there must be a mistake in the code...

The Javascript console in Firefox tells me this:
Fout document.getElementById("warning") has no properties.

Do you have any idea?
LukeakaDanish
can i see the entire document for your page please?
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.