Solved

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

Posted on 2004-10-25
247 Views
Last Modified: 2012-05-05
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
Question by:Caiapfas
    10 Comments
     
    LVL 21

    Expert Comment

    by:MogalManic
    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
     
    LVL 2

    Author Comment

    by:Caiapfas
    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
     
    LVL 6

    Expert Comment

    by:cwkhang
    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
     
    LVL 6

    Expert Comment

    by:cwkhang
    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
     
    LVL 6

    Expert Comment

    by:cwkhang
    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
     
    LVL 2

    Author Comment

    by:Caiapfas
    I'd perfer a php way to do this...for the automatic redirect...plus page blank out
    0
     
    LVL 21

    Expert Comment

    by:MogalManic
    Just replace your PHP page for the .html files in our samples
    0
     
    LVL 2

    Author Comment

    by:Caiapfas
    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
     
    LVL 21

    Expert Comment

    by:MogalManic
    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
     

    Accepted Solution

    by:
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: MongoDB Object-Document Mapper for NodeJS

    NodeJS (JavaScript on the server) is awesome, but some developers get confused about NoSQL when it comes to working in Node with MongoDB (NoSQL database). Do you need a better explanation of how to use Node.js with MongoDB? The most popular choice is the Mongoose library.

    Suggested Solutions

    Title # Comments Views Activity
    dog bark java program 15 57
    Conceptualizing a Lessons Learned database in C# 4 66
    sumHeights  challenge 17 34
    strCount chalenge 3 12
    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now