ToddAtWSU Posted March 17, 2007 Share Posted March 17, 2007 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 } ?> Link to comment https://forums.phpfreaks.com/topic/43160-problem-checking-for-scripting-or-no-scripting/ Share on other sites More sharing options...
kenrbnsn Posted March 17, 2007 Share Posted March 17, 2007 PHP executes on the server before the browser sees the code. It has no clue about what Javascript is. Ken Link to comment https://forums.phpfreaks.com/topic/43160-problem-checking-for-scripting-or-no-scripting/#findComment-209584 Share on other sites More sharing options...
ToddAtWSU Posted March 17, 2007 Author Share Posted March 17, 2007 So is there anyway to avoid outputting the rest of my page is scripting is disabled? Link to comment https://forums.phpfreaks.com/topic/43160-problem-checking-for-scripting-or-no-scripting/#findComment-209589 Share on other sites More sharing options...
iceman400 Posted March 17, 2007 Share Posted March 17, 2007 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> Link to comment https://forums.phpfreaks.com/topic/43160-problem-checking-for-scripting-or-no-scripting/#findComment-209599 Share on other sites More sharing options...
ToddAtWSU Posted March 18, 2007 Author Share Posted March 18, 2007 So I will have to have an intermediate page to check if Javascript is enabled? What do you mean by "postback stuff here;". I have really never used javascript besides the onclick functionality. Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/43160-problem-checking-for-scripting-or-no-scripting/#findComment-209684 Share on other sites More sharing options...
per1os Posted March 18, 2007 Share Posted March 18, 2007 www.webmonkey.com read up on JavaScript. It is a very interesting language. Link to comment https://forums.phpfreaks.com/topic/43160-problem-checking-for-scripting-or-no-scripting/#findComment-209773 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.