Link to home
Start Free TrialLog in
Avatar of Caiapfas
Caiapfas

asked on

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
Avatar of MogalManic
MogalManic
Flag of United States of America image

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>

Avatar of Caiapfas
Caiapfas

ASKER

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
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>
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
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>
I'd perfer a php way to do this...for the automatic redirect...plus page blank out
Just replace your PHP page for the .html files in our samples
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....
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
ASKER CERTIFIED SOLUTION
Avatar of grinchy
grinchy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial