• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

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
0
Caiapfas
Asked:
Caiapfas
  • 3
  • 3
  • 3
  • +1
1 Solution
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now