How do I Javascript redirect without Javascript?

Discussion in 'JavaScript' started by johnsmith153, May 14, 2008.

  1. #1
    I want to show a php page with heavy php code.

    After all php processing is done, it then:

    1. Uses <noscript> in the <head> to check if js on or not - if so, no problem
    2. If not, will show this on screen:

    Javascript not on

    Turn on then click here / or, click to view basic version of our site (js not needed)

    What I need to do is, if js is not on, then prevent the page from viewing, including all my echo php commands that are in the body tag below.

    Originally I had an idea to automatically redirect to a nojavascript.html page - but cant as I have no js to do a location.href.

    I need (1) a way to redirect without js OR
    (2) A way to prevent showing page if js is not on

    Oh, I don't use loads of unnecessary js, but I use DHTML/AJAX a lot so would look strange and not have any useability.
     
    johnsmith153, May 14, 2008 IP
  2. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #2
    My idea is, put files in separated directories (althought it seems "redundant" somewhat).

    For example, create "/with-js" dir, with all files that are supposed to be viewed with js.

    And create "/without-js" dir

    Now, lets move to the upper dir, lets create a welcome page (splash screen, you can name it :D), for example an "index.php"

    So here's the scenario.
    Visitors go to "something.com/index.php" and see the welcome page.
    If the JS is on, s/he must visit the "something.com/with-js".
    If it is off, s/he must visit the "something.com/without-js".

    Ok now the question is how to redirect visitors, based on the JS setting.
    Lets go to index.php

    
    <script>
    function lets_check() {
       document.getElementById('clicked').href = './with-js';
    }
    </script>
    <body onload="lets_check()">
    
       <h1>Welcome Here</h1>
    
       <a href="./without-js" id="clicker">Click here to continue</a>
    </body>
    
    HTML:
     
    xrvel, May 14, 2008 IP
  3. johnsmith153

    johnsmith153 Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the idea, but I have just thought of an even better way. I have tested and works brilliantly.

    <noscript>
    <meta http-equiv="Refresh" content="0; URL=http://www.turn-it-on-for-gods-sake.com" />
    </noscript>
     
    johnsmith153, May 14, 2008 IP