need to check if user has javascript enabled and display a error msg.

I need a php script that checks to see if they have javascript enabled and if not displays a error page.
Have tried to make this a few times and can't make it work.

Much Thanks..
Caiapfas
LVL 2
CaiapfasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MogalManicCommented:
Try this:  (It should work for IE 4.0 and above and Netscape 4.x)

<script LANGUAGE="JavaScript">
     <!-- document.write("Hello World.") -->
</script>
<noscript>
     <b>Please>/b> try this page for browsers that can not handle SCRIPTing.
     <a HREF="http://www.foo.com/alternate.html">Simple Text Page</a>
</noscript>

0
CaiapfasAuthor Commented:
I need it to be php :Reason so i can redirect them to a page telling them how to enable it.. or a page that doesnt need js
0
cwkhangCommented:
u want to redirect

<SCRIPT LANGUAGE="JavaScript">
if (!navigator.javaEnabled())                   //if javascript is not enabled, then redirect to nojava.html
{
           document.location = "nojava.html";
}
</SCRIPT>
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

cwkhangCommented:
ops... i see you want to test javascript
the code above is to test java
sory bout tat

as javascript is disable, surely u can't use javascript to test or to do the redirect
0
cwkhangCommented:
umm, how about try to do this way

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
window.location="http://www.abc.com/javascript-page.html";  //if javascript is enabled, redirect to page that need js
// End -->
</script>
          <!--else just telling them how to enable it over here or put ur no-java page here-->
<noscript>
It appears that your browser does not support JavaScript, or you have it disabled.  This site is best viewed with JavaScript enabled.<p>If JavaScript is disabled in your browser, please turn it back on then reload this page.<p>Or, if your browser does not support JavaScript,
click <a href="http://www.your-web-site-address-here.com/no-javascript-page.html">here</a>.
</noscript>
0
CaiapfasAuthor Commented:
I'd perfer a php way to do this...for the automatic redirect...plus page blank out
0
MogalManicCommented:
Just replace your PHP page for the .html files in our samples
0
CaiapfasAuthor Commented:
yes, i am aware that i can change the link..

but i want a php script that actual does the check and stops the page from being displayed and then redirects...
I can't add a javaascript check page in the sequence of pages that loads....
0
MogalManicCommented:
The PHP server cannot obtain that kind of information about the clients browser.  You could design a page that sends to the server a parameter that says that javascript is enabled or not enabled.  Then the PHP can store that value in a session variable.  Later pages can then act on the results of that variable.

EG.
  Login.PHP - sends javascript 'enabled' as 1 or 0 when user clicks login (It also sends username/password)
  AuthenticateUser.PHP - Stores 'enabled' in session
  ProcessOrder.PHP - Does more vigorious validation if 'enabled' is 0
0
grinchyCommented:
This will do what you want almost completely transparently

<html>
<head>
<?
if($_GET['check']!='ok')
{
?>

<script>
window.location='?check=ok'
</script>


</head>
<body>
PAGE FOR NONE JS USERS


<?
}

else
{
?>

</head>
<body>
PAGE FOR JS USERS

<?
}
?>

</body>
</html>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.