javascript browser sniffer?
4 posts
• Page 1 of 1
javascript browser sniffer?
does anyone have a simple javascript browser sniffer? I want a user to be able to go to my index.html and have the script detect their screen res and browser type/version, and pick the appropriate css to apply to the index.html.
thanks.
Oh one more thing...can this be done within a separate .js file? It should be able to right?
Lookd likr there are lots of sniffers for this :
http://www.google.com/search?lr=&ie=UTF ... %20sniffer
I would first try the one at SourceForge.net
I noticed you didn't replied whether you have succeded with the javascripts so I figured since I have some spare time now to properly answer your question
So, for the browser type detection you can use this :
For the screen resolution you can use this :
In case you also need to detect the window dimensions try this :
All these scripts will popup a window for you to check they really work - in the actual page you won't probably need the window.alert(...) instruction.
Hope this helps you and I apologize for the delay!
So, for the browser type detection you can use this :
- Code: Select all
<script language="JavaScript" type="text/javascript">
var uA = navigator.userAgent;
var browserType = "unknown";
if (uA.indexOf("Opera") > -1) {
browserType = "Opera";
} else if (uA.indexOf("Safari") > -1) {
browserType = "Safari";
} else if (uA.indexOf("Konqueror") > -1) {
browserType = "Konqueror";
} else if (uA.indexOf("Gecko") > -1) {
browserType = "Mozilla";
} else if (uA.indexOf("MSIE") > -1) {
browserType = "Internet Explorer";
}
window.alert(browserType);
</script>
For the screen resolution you can use this :
- Code: Select all
window.alert(screen.availWidth + " x " +
screen.availHeight + " pixels");
In case you also need to detect the window dimensions try this :
- Code: Select all
<script language="JavaScript" type="text/javascript">
window.onload = function() {
if (window.innerWidth) {
window.alert("inner: " + window.innerWidth +
" x " + window.innerHeight +
" pixels\nouter: " + window.outerWidth +
" x " + window.outerHeight + " pixels");
} else {
with (document.body) {
window.alert(clientWidth + " x " +
clientHeight + " pixels");
}
}
}
</script>
All these scripts will popup a window for you to check they really work - in the actual page you won't probably need the window.alert(...) instruction.
Hope this helps you and I apologize for the delay!
4 posts
• Page 1 of 1
Return to HTML, CSS, and Scripts
Who is online
Users browsing this forum: No registered users and 6 guests