faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 9 people (78%) answered Yes
Recently 7 of 9 people (78%) answered Yes

Entry

How do I know if my clients browser supports JavaScript, so to redirect him to another page?

Apr 6th, 2008 18:43
ha mo, Jean-Bernard Valentaten, Joćo Martins,


Well, you can't really know it. You can only "guess" it.
I use the following trick, when I need to determine whether a user has 
js enabled or not:
First you create a webpage, that has the following meta-tag
<meta http-equiv="refresh" content="1; URL=./index_withoutjs.html">
The "refresh" will tell the browser to refresh the page after a certain 
ammount of seconds, specified in the content (1 second here) and use 
the page given through the URL= statement (where you should write down 
the page that won't use js!!!)
After that write a little script-block like the following:
<script language="JavaScript">
<!--
  document.location = "./index_usingjs.html"
//--
</script>
Your index.html should look like this now:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title>Do you use js or not?</title>
	<meta http-equiv="refresh" content="1, 
URL=./index_withoutjs.html">
	<script language="JavaScript">
	<!--
		document.location = "./index_usingjs.html";
	//-->
	</script>
</head>
<body>
<p>You're beeing forwarded in one second.<br>If not, please follow this 
link: <a href="./index_withoutjs.html">here</a>!</p>
<!-- If the user still see's the page after one second, his js is not 
activated for sure!!! (and the meta didn't work for his browser)-->
</body>
</html>
This little trick will decide where your user goes today *g*
HTH
Jean
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com