javascript - Show or Hide html content with java script -
i want show or hide html java script if (condition)
want able hide html when users use example firefox , show content when use browser.
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript"> var nver = navigator.appversion; var nagt = navigator.useragent; var browsername = navigator.appname; var fullversion = ''+parsefloat(navigator.appversion); var majorversion = parseint(navigator.appversion,10); var nameoffset,veroffset,ix; // in opera, true version after "opera" or after "version" if ((veroffset=nagt.indexof("opera"))!=-1) { browsername = "opera"; fullversion = nagt.substring(veroffset+6); if ((veroffset=nagt.indexof("version"))!=-1) fullversion = nagt.substring(veroffset+8); } // in msie, true version after "msie" in useragent else if ((veroffset=nagt.indexof("msie"))!=-1) { browsername = "microsoft internet explorer"; fullversion = nagt.substring(veroffset+5); } // in chrome, true version after "chrome" else if ((veroffset=nagt.indexof("chrome"))!=-1) { browsername = "chrome"; fullversion = nagt.substring(veroffset+7); } // in safari, true version after "safari" or after "version" else if ((veroffset=nagt.indexof("safari"))!=-1) { browsername = "safari"; fullversion = nagt.substring(veroffset+7); if ((veroffset=nagt.indexof("version"))!=-1) fullversion = nagt.substring(veroffset+8); } // in firefox, true version after "firefox" else if ((veroffset=nagt.indexof("firefox"))!=-1) { browsername = "firefox"; fullversion = nagt.substring(veroffset+8); } // in other browsers, "name/version" @ end of useragent else if ( (nameoffset=nagt.lastindexof(' ')+1) < (veroffset=nagt.lastindexof('/')) ) { browsername = nagt.substring(nameoffset,veroffset); fullversion = nagt.substring(veroffset+1); if (browsername.tolowercase()==browsername.touppercase()) { browsername = navigator.appname; } } // trim fullversion string @ semicolon/space if present if ((ix=fullversion.indexof(";"))!=-1) fullversion=fullversion.substring(0,ix); if ((ix=fullversion.indexof(" "))!=-1) fullversion=fullversion.substring(0,ix); majorversion = parseint(''+fullversion,10); if (isnan(majorversion)) { fullversion = ''+parsefloat(navigator.appversion); majorversion = parseint(navigator.appversion,10); } if( browsername == "chrome") document.write("what should put @ line hide test div?"); else document.write("access denied!,what should put @ line hide test div?"); </script> </head> <body> <div id = "test"> <p>test div</p> </div> </body> </html>
i want show or hide content if condition.i use code prevent opening website in common browsers instead of vb browser designed website.
add class css:
.hidden { visibility:hidden; }
based on if
statement:
a = document.getelementbyid('test') a.classname = a.classname + ' hidden'
of course none of code work javascript disabled.
Comments
Post a Comment