Click to See Complete Forum and Search --> : detecting css enabled?
96turnerri
11-08-2003, 08:55 AM
hi guys i tried doing a search for this but it returned an error as the minimum length of a search word is 4 letters and css is obviuosly 3
I would like know how can i detect whether a users browser has css enabled?, a document.write function is also need to wirte say css enabled? yes or no
Thanks v much
Rich
jochem
11-08-2003, 07:49 PM
You might find your answer within this forum at:
http://forums.webdeveloper.com/showthread.php?s=&threadid=19591
Cheers, Jochem :cool:
96turnerri
11-09-2003, 06:37 AM
ok thanks ill try and cut out the bit i need if i cant ill post again. thanks alot
Rich
96turnerri
11-09-2003, 08:04 AM
nope :( couldnt dig it out of there, cant seem to work out which bit i need, can someone please help :confused:
zachzach
11-09-2003, 09:23 AM
well try the navigator object, like theres a navigator.javaEnabled() and that returns true/false, so maybe theres a cssEnabled(), also, find out how to get the name of the browser, and then have a list of which browsers work with css, also, to find out if its a DOM/IE, use this code
if(document.all) {
browser="DOM/IE"
}
and to find out netscape:
if(document.layers) {
browser="Netscape"
}
96turnerri
11-09-2003, 09:58 AM
:confused: :confused: :confused: :confused: :confused: im completly at a loss, what ever i try it doesnt work, ive tried combining scripts, doing what you said zach lots of things even searching on search engines, some body some where must know the answer?? plz help :(
Rich
zachzach
11-09-2003, 10:02 AM
well I KNOW, because I've tested, and re-tested, this script works:
first declare browser=""
browser=""
to detect IE browser
if(document.all) {
browser="IE"
}
And to detect a netscape browser:
if(document.layers) {
browser="Netscape"
}
to detect Mozzila/Opera:
if(browser=="") {
browser="Mozzila/Opera"
}
zachzach
11-09-2003, 10:13 AM
ok heres another more specific code that works even better:
first, declare browser="", and declare version=""
browser="";
version="";
then, find the browser and version:
if(navigator.appName=="Netscape") {
browser="Netscape"
version=navigator.appVersion
}
if (navigator.appVersion.indexOf("MSIE")!=-1){
temp=navigator.appVersion.split("MSIE")
version=parseFloat(temp[1])
}
if (navigator.userAgent.indexOf("Opera")!=-1) {
browser="Opera"
version=""
//its almost imposible to detect opera's version because its
//stored directly next to the opra, like this: Opera/6
}
well, there, you have either Netscape, IE, or Opera, and you have the version number for them, now just find out which browser and version supports CSS!!!
[/code]
zachzach
11-09-2003, 10:24 AM
again, another way...(lol, more corrections and additions!):
set browser to nothing, and version to nothing:
browser=""
version=""
find out which browser and version the client's using:
if(document.getElementById && !document.all) {
browser="Netscape"
version="6"//and up
}
if(document.getElementById && document.all) {
browser="IE"
version="5"//and up
}
if(document.layers) {
browser="Netscape"
version="4"//not up or down, just 4
}
if(document.images && !document.layers) {
browser="Netscape"
version="3"
}
note:this code is great, if say, you wantyed to do an image rollover using document.images[], but some old browsers dont support it, just do:
if(document.images) {
do-the-roll-over-funtion-here()
}else{
alert('The image rollover does not work with your browser, please upgrade your browser to enjoy our interactive pages.')
}
not bad, eh?
zachzach
11-09-2003, 10:27 AM
and even more things to the navigator object, heres all the ones that you can use for something(theres probably one I missed, but these are the importent ones:)
navigator.appCodeName -- The code name of browser (ie: Mozilla)
navigator.appName -- The name of the browser (ie: Microsoft Internet Explorer)
navigator.appVersion -- Version information of the browser (ie: 4.75 [en] (Win98; U)
navigator.userAgent -- String passed by browser as user-agent header. (ie: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Hotbar 3.0))
navigator.platform -- The platform of the client's computer. JavaScript 1.2 property. (ie: Win32)
theres all the importent ones!
zachzach
11-09-2003, 10:30 AM
I personaly thing the object detection is great, because you dont have to know what browser it is...Ill look into seeing if I could do something like:
if(CSS) {
function()
}
zachzach
11-09-2003, 10:38 AM
here you go, If you want to use some CSS, do this
<script language="javascript">
browser="";
version="";
if(navigator.appName=="Netscape") {
browser="Netscape"
version=navigator.appVersion
}
if (navigator.appVersion.indexOf("MSIE")!=-1){
temp=navigator.appVersion.split("MSIE")
version=parseFloat(temp[1])
browser="IE"
}
if (navigator.userAgent.indexOf("Opera")!=-1) {
browser="Opera"
version="?"
}
function usecss() {
if(browser == "IE") {
if(version => 3) {
=========csscode here=========
}
}
if(browser="Netscape") {
if(version => 4) {
=========csscode here=========
}
}
}
</script>
96turnerri
11-09-2003, 10:52 AM
omg thanks for all the work zach but im even more cinfused now lol, no matter how many times i read it
which one should i use?
and where the document.write(",cssenabled,");
bit gone?
:confused: :confused:
zachzach
11-09-2003, 11:22 AM
use this code:
<script language="javascript">
browser="";
version="";
if(navigator.appName=="Netscape") {
browser="Netscape"
version=navigator.appVersion
}
if (navigator.appVersion.indexOf("MSIE")!=-1){
temp=navigator.appVersion.split("MSIE")
version=parseFloat(temp[1])
browser="IE"
}
if (navigator.userAgent.indexOf("Opera")!=-1) {
browser="Opera"
version="?"
}
function usecss() {
if(browser == "IE") {
if(version => 3) {
document.write('You have CSS enabled in a IE browser, version' + version)
}
}
if(browser="Netscape") {
if(version => 4) {
document.write('You have CSS enabled in a Netscape browser, version' + version)
}
}
}
</script>
96turnerri
11-09-2003, 12:02 PM
that come up with no errors, but i do get a blank screen lol
zachzach
11-10-2003, 02:42 PM
im not trying to insult you but...DUH!Lol!YOU DIDN'T RUN THE FUNCTION LOOOOOOOOOOOOOOOOOOL!
<script language="javascript">
browser="";
version="";
if(navigator.appName=="Netscape") {
browser="Netscape"
version=navigator.appVersion
}
if (navigator.appVersion.indexOf("MSIE")!=-1){
temp=navigator.appVersion.split("MSIE")
version=parseFloat(temp[1])
browser="IE"
}
if (navigator.userAgent.indexOf("Opera")!=-1) {
browser="Opera"
version="?"
}
function usecss() {
if(browser == "IE") {
if(version => 3) {
document.write('You have CSS enabled in a IE browser, version' + version)
}
}
if(browser="Netscape") {
if(version => 4) {
document.write('You have CSS enabled in a Netscape browser, version' + version)
}
}
}
</script>
zachzach
11-10-2003, 03:11 PM
OK, this is slightly off-topic, but you might find this code handy. Its like the ultimate collection of everything that could be messed up using different browsers(I'm starting with images. I'm going to keep adding on to it, too. Id also like any additions/comments/suggestions.)
<script language="javascript">
browser="";
version="";
if(navigator.appName=="Netscape") {
browser="Netscape"
version=navigator.appVersion
}
if (navigator.appVersion.indexOf("MSIE")!=-1){
temp=navigator.appVersion.split("MSIE")
version=parseFloat(temp[1])
browser="IE"
}
if (navigator.userAgent.indexOf("Opera")!=-1) {
browser="Opera"
version="Unknown"
}
if(browser == "") {
browser="Unknown"
version="Unknown"
}
function imagerollover(idofimage, oldsrc, newsrc, gobackyesorno, backorfoward) {
var _image = (document.all) ? document.all[idofimage] : document.getElementById(idofimage)
if(gobackyesorno.toLowerCase() == "yes") {
if(backorfoward.toLowerCase() == "foward") {
_image.src=newsrc
}else{
_image.src=oldsrc
}
}else{
_image.src=newsrc
}
}
//example use:
//<img src="the-first-image-src.GIF" onmouseover='imagerollover(this.id, this.src, "the-second-image-src.GIF", "YES", "foward")' onmouseout='imagerollover(this.id, "the-first-image-src.GIF", this.src, "YES", "back")'
function switchvisibility(idofimage, hideorshow) {
_id = (document.all) ? document.all[idofimage] : document.getElementById(idofimage)
if(hideorshow.toLowerCase() == "hide") {
(document.all) ? _id.style.visibility="hidden" : the-netscape-version-is-needed!
}
if(hideorshow.toLowerCase() == "show") {
(document.all) ? _id.style.visibility="visible" : the-netscape-version-is-needed!
}
if(hideorshow.toLowerCase() == "auto") {
(_id.style.visibility == "visible") ? _id.style.visibility == "hidden" : _id.style.visibility == "visible"
}
//example use:
//<div style="visibility: visible" onmouseover='switchvisibility(this.id, "AUTO")'
//AUTO,HIDE,SHOW--choices for switchvisibility()
</script>
FIXEDSCRIPT
oh, and by the way I found an error, heres the fixed script:
<script language="javascript">
browser="";
version="";
if(navigator.appName=="Netscape") {
browser="Netscape"
version=navigator.appVersion
}
if(navigator.appVersion.indexOf("MSIE")!=-1){
temp=navigator.appVersion.split("MSIE")
version=parseFloat(temp[1])
browser="IE"
}
if (navigator.userAgent.indexOf("Opera")!=-1) {
browser="Opera"
version="Unknown"
}
if(browser == "IE") {
if(version >= 3) {
document.write('You have CSS enabled in a IE browser, version' + version)
}
}
if(browser=="Netscape") {
if(version >= 4) {
document.write('You have CSS enabled in a Netscape browser, version' + version)
}
}
</script>
96turnerri
11-11-2003, 05:55 PM
i did run the script you cheeky b*****d lol only jkin m8 that php login script you want is coming on good sent you a pm about it :p
96turnerri
11-11-2003, 05:58 PM
argh i see now it works it wasnt just me :p