Jump to content

Problem checking for scripting or no scripting.


ToddAtWSU

Recommended Posts

I have a page with Javascript inside it so I want to check if the user has scripting enabled before displaying my page. I am successfully able to check if they have scripting enabled since when I turn it off my stuff inside the <noscript> tag appears and when I have it on it doesn't appear. What I also wanted to do was create a variable that held a true or false if scripting is enabled. I originally said inside the <noscript> tags I put inside a <?php tag and changed the variable to false saying scripting is disabled. Then outside the <noscript> tag I did a check and if scripting was false then just ignore all the rest of my code except the </body> and </html> tags. Unfortunately this doesn't work as I guess even is scripting is enabled it still executes any code inside the <noscript> tag. Is there anyway to do what I want to do? Here is what the snippet of my code looks like.

 

<?php
   }
   else
   {
      $scripting = true;
?>

<html>
   <head>
      <title>Submit Top Ten</title>
   </head>

   <body bgcolor="#000000" text="#FFFF00" link="#FF9900" vlink="#CC9900">

      <noscript>
         Your browser does not support Javascript. This page will not work correctly.
         <br><br>
         To enable Javascript in Internet Explorer 6:<br>
         Click Internet Options from inside the Tools Menu.<br>
         Click the Security Tab.<br>
         Click the Custom Level button.<br>
         Scroll down towards the bottom of the list where Scripting is located.<br>
         Choose Enable for "Active Scripting," "Allow paste operations via script," and "Scripting of Java applets."<br><br>
         To enable Javascript in FireFox:<br>
         Click Options from inside the Tools Menu.<br>
         Choose the Content button.<br>
         Click the Checkmark next to "Enable Javascript."<br>
         <?php
            global $scripting;
            $scripting = false;
         ?>
      </noscript>

      <?php
         global $scripting;
         if( $scripting != false )
         {
      ?>

      <form action="topTen.php" method="post">
         <font face="Arial">
            ...
         </font>
      </form>
      <?php
         }
      ?>
   </body>
</html>
<?php
   }
?>

i think that you would have to create a seperate page where u have a <noscript> tag with the text you want displayed if javascript is disabled, and in the same file in a <script> tag you do a post back to your original php page. if the php page is called by the javascript post back, then you know javascript is enabled. if there's no postback, the <noscript> text is displayed and you dont have to send the rest of the stuff to the client.

 

something like:

//this is the page that checks for javascript
<script language = "javascript">
postback stuff here;
</script>

<noscript>
sorry dude, you have javascript disabled!
</noscript>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.