Jump to content

javascript detect browser


SN1P3R_85

Recommended Posts

This isn't really a php question, but im tired of posting on the javascript page and having to wait an hour till i even get a single reply. Im sure many of you know javascript if you know php. In a code, i am calling different css files based on the browser type. What it does so far is call the css file, but doesn't execute any of the html, so i get a background color, and thats it. I call the js function in the body tag: <body onLoad="check_brwz();">

 

here is the javascript code:

 

<script type="text/javascript">

<!--

function check_brwz() //checks for browser type so it will apply the correct style format

{

function browser() //sets browser name and version

{

this.name = navigator.appName;

this.version = navigator.appVersion;

}

 

browse = new browser();

 

if (browse.name == 'Netscape') //sets the correct style format

{

document.write('<link rel="stylesheet" type="text/css" href="/css/moz_main.css" />');

document.write("hello");

}

else if (browse.name == 'Microsoft Internet Explorer')

{

document.write('<link rel="stylesheet" type="text/css" href="/css/ie_main.css" />');

}

else if (browse.name == 'Opera')

{

document.write('<link rel="stylesheet" type="text/css" href="/css/opera_main.css" />');

}

else //default style format if browser type is unkown

{

alert('your browser is too old or unkown, settings will be set by default to fit Mozilla');

document.write('<link rel="stylesheet" type="text/css" href="/css/moz_main.css" />');

}

alert(browse.name);

}

//-->

</script>

Link to comment
https://forums.phpfreaks.com/topic/132879-javascript-detect-browser/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.