|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Anyone good with javascript (browser detection --> css?)
Hi everyone. I don't know if anyone will know the answer to this but I figured I'd try anyway >.<
I am trying to use a browser detection script for my new website but I'm not quite sure how to make it to include Safari in the detection. Can anyone help? Thanks in advance. Here is what I have so far: Code:
if(-1 != navigator.userAgent.indexOf("MSIE"))
{
// Internet Explorer
document_write('.. rel="stylesheet" type="text/css" href="ie.css">');
}
else if (-1 != navigator.userAgent.indexOf("Mozilla"))
{
// Netscape
document_write('.. rel="stylesheet" type="text/css" href="netscape.css">');
}
else
{
// other
document_write('.. rel="stylesheet" type="text/css" href="other.css">');
}
|
|
#2
|
|||
|
|||
|
Hi,
I'm not so strong on Javascript myself, but have some knowledge of it. To include safari in the detection script, I would sudjest you have javascript look for something that sets safari appart from other browsers. here is a script that will give you all the details about your current browser, hope this helps. Code:
javascript
function test_browser() {
var version = navigator.appVersion;
var name = navigator.appName;
var language = navigator.language;
var code = navigator.appCodeName;
var agent = navigator.userAgent;
var platform = navigator.platform;
var windowFeatures = 'Width=500, Height=350, Toolbar=no, Scrollbars=yes, Menubar=no';
myWin = window.open('','',windowFeatures);
myWin.document.write('<HTML><HEAD><TITLE>uw browser');
myWin.document.write('</TITLE></HEAD><BODY Bgcolor="Ivory">');
myWin.document.write('<H2>Details of your browser:</H2>');
myWin.document.write('<TABLE Cellspacing=5><TR><TD>Naam:</TD><TD>', Name, '</TD></TR>');
myWin.document.write('<TR><TD>Taal:</TD><TD>', language, '</TD></TR>');
myWin.document.write('<TR><TD>Version:</TD><TD>', versie, '</TD></TR>');
myWin.document.write('<TR><TD>Browser Codenaam:</TD><TD>', code, '</TD></TR>');
myWin.document.write('<TR><TD>Useragent:</TD><TD>', agent, '</TD></TR>');
myWin.document.write('<TR><TD>Platform:</TD><TD>', platform, '</TD></TR>');
myWin.document.write('</TABLE>');
myWin.document.write('<FORM><DIV Align=center><Input Type="button" Value="sluiten" onClick="self.close()">');
myWin.document.write('</DIV></FORM>');
myWin.document.write('</HTML>');
}
and then put this on the page: Code:
javascript
<input type="submit" onClick="test_browser()" title="check my browser"> also check out W3Schools. They have alot of usefull info on javascript |
|
#3
|
||||
|
||||
|
Using Javascript to present different stylesheets to different browsers is usually frowned upon. Typically the difference in browser-rendering is minimal, and there's often CSS hacks to get around that. You might want to consider a different route.
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
|
#4
|
||||
|
||||
|
Indeed. Usually when you need browser-detection, you're only introducing browser incompatibility. Just validate your HTML and CSS using the validators provided by the W3C and it should pretty much work on all existing browsers.
__________________
This is my code. Is it not nifty? "The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools." ---Douglas Adams Join the Itsacon fanclub! Zero Tolerance: Spammers banned so far: 263
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Web Design > Advanced Web Development > Anyone good with javascript (browser detection --> css?) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|