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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.