Jump to content

Browser detect/ user agent


LMarie

Recommended Posts

Hi

I have created a log in site for a service but the service only works for IE version 6 and up. I want the client to get a pop up if they are using a different browser or version.

 

The first page contains a log on link that takes the user to a log in page where they fill out username and password. I want the error message to pop up when they get to this page.

 

I have found a javascript on w3schools but it doesn't work as its supposed to.

 

On w3 schools it said:

"IMPORTANT! The version number is WRONG in IE 5.0 or later! Microsoft starts the appVersion string with the number 4.0. in IE 5.0 and IE 6.0!!! Why did they do that??? However, JavaScript is the same in IE6, IE5 and IE4, so for most scripts it is OK."

http://www.w3schools.com/js/js_browser.asp

 

The script:

<html><head>
<script type="text/javascript">
function detectBrowser(){
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
if ((browser=="Microsoft Internet Explorer")  && (version=5))  {  
alert("OK");  }
else  {  
alert("Wrong browser or version!");  }}
</script></head>
<body onload="detectBrowser()">
</body></html>

 

Is it possible to make som changes to this script to make it work?

 

Iv tried to use http user agent but this only blocks firefox, and not opera and IE . Is it easier to user "user agent"? If so how do i block opera as well as firefox?

 

Thankful for any tips :)

Link to comment
https://forums.phpfreaks.com/topic/175769-browser-detect-user-agent/
Share on other sites

Great.. It works.

Thank you :) Much easier too.

 

The script i used:

<html>
<head>
<![if !IE]>
<SCRIPT LANGUAGE="Javascript">
alert("You need to use IE 6 or above to get access to this service");
</SCRIPT>
<![endif]>
<!--[if lte IE 5]>
<SCRIPT LANGUAGE="Javascript">
alert("You need to use IE 6 or above to get access to this service");
</SCRIPT>
<![endif]-->
</head>
</html>

 

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.