Joshua4550 Posted March 24, 2010 Share Posted March 24, 2010 Ok so basically what i've done, is find the screen size using javascript, assigned it to a variable, and this must work because when i echo it it shows the proper size on the page. I also did this with whether they have flash 8 or later, or not. should set the var to 1 if so, or 0 if not. Again, when i echo it, it shows the right number, but when i ask php if its 1, it doesnt work? Heres the codes (Not full, but the codes appropriate)... //$has_flash = 1 or 0 $has_flash = ' <script type="text/javascript"> if (!FlashDetect.versionAtLeast() { // Dont have flash 8 or later document.write(0); } else { document.write(1); } </script> '; Heres the code to echo it (works apparently) <p>has flash: ' . $has_flash . '</p> But HERES THE PROBLEM. When I do the following, it never works out. if ($has_flash == 1) { $menu = ' HAI U HAV FLASH '; } else { $menu = 'U DONT HAV FLASH< I R SAD'; } echo $menu; It always goes for the else statement. WHY? ALL help appreciated. Thanks alot Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted March 24, 2010 Share Posted March 24, 2010 Because Javascript is client side and php is server side. You cannot set a server side variable (php) to the value of a client side result using javascript (not without using ajax). All you are doing is assigning a string to $has_flash containing javascript code. if you echo it out it will run the javascript in the client browser. Quote Link to comment Share on other sites More sharing options...
Joshua4550 Posted March 24, 2010 Author Share Posted March 24, 2010 Oh I see. So what's the best way of doing what i'm trying to achieve, do you think? Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted March 24, 2010 Share Posted March 24, 2010 Please explain in detail what you are trying to achieve. Quote Link to comment Share on other sites More sharing options...
Joshua4550 Posted March 24, 2010 Author Share Posted March 24, 2010 A way to check whether they have flash 8 or later (which evidently can be done in javascript), but then i need to store the values in a serverside variable, so I can use them in php like you saw in the first post. I'm not sure how i'd go about doing this, especially if it needs ajax, because 'm VERY new to ajax too. Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted March 24, 2010 Share Posted March 24, 2010 And why do you need to store in a server side variable? If you are using the result of the test to display certain elements on the screen then this call all be acheived client side. Quote Link to comment Share on other sites More sharing options...
Joshua4550 Posted March 24, 2010 Author Share Posted March 24, 2010 Hm. I suppose it could be. Would I just do this.. $flashtest = ' <script type="text/javascript"> if (!FlashDetect.versionAtLeast() { // Dont have flash 8 or later document.write("U need flash 8"); } else { document.write("U have flash 8"); } </script> '; echo $flashtest; ? Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted March 24, 2010 Share Posted March 24, 2010 Take a look at http://www.adobe.com/products/flashplayer/download/detection_kit/ Quote Link to comment Share on other sites More sharing options...
Joshua4550 Posted March 24, 2010 Author Share Posted March 24, 2010 I looked at the exampe and it was pretty much what I put, yet mine doesnt echo? any idea why? $menu = ' <script type="text/javascript"> if (!FlashDetect.versionAtLeast() { // Dont have flash 8 or later var content = \' <b><font color=#FF0000> Install flash 8 or later! </font></b> \'; document.write(content); } else { var content = \' <p>Hi, you have flash 8 or later.</p> \'; document.write(content); } </script> '; echo ' <body> <noscript class="ERROR">Please enable JavaScript</noscript> <div id="main"> ' . $menu . ' </div> </body> '; It doesnt echo though. Argh, please help xD Quote Link to comment Share on other sites More sharing options...
priti Posted March 24, 2010 Share Posted March 24, 2010 Jquery will help you more here: 1. download jquery 2. add the <script> tags 3. $(document).ready(function() { if (!FlashDetect.versionAtLeast() { // Dont have flash 8 or later $('#main').html("don't have flash 8"); } else { $('#main').html("you have flash 8"); } }); and you are done!! Quote Link to comment Share on other sites More sharing options...
Joshua4550 Posted March 24, 2010 Author Share Posted March 24, 2010 Thanks, but may I ask why javascript alone wont write it onto my page? Because it works as so on the example by adobe. Thanks Quote Link to comment Share on other sites More sharing options...
priti Posted March 24, 2010 Share Posted March 24, 2010 try $menu = '<script type="text/javascript"> if (!FlashDetect.versionAtLeast() { // Dont have flash 8 or later var content = "<b><font color=#FF0000>Install flash 8 or later!</font></b>"; document.write(content); } else { var content = "<p>Hi, you have flash 8 or later.</p>"; document.write(content); } </script>'; Quote Link to comment Share on other sites More sharing options...
Joshua4550 Posted March 24, 2010 Author Share Posted March 24, 2010 Oh, it seems to work, but when i try doing ordered lists, it doesnt work :@ Quote Link to comment Share on other sites More sharing options...
Joshua4550 Posted March 24, 2010 Author Share Posted March 24, 2010 Kk please help me out here, i'm stressin lol. Heres my actual code, it won't fuckin' echo anything $menu = '<script type="text/javascript"> if (!FlashDetect.versionAtLeast() { // Dont have flash 8 or later var content = "<b><font color=#FF0000>HOME, TUTORIALS<br /> Install flash 8 or later to view the proper navigation toolbar! </font></b>"; document.write(content); } else { var content = "<ul id=\"menu\" class=\"menu\"> <li> <a href=\"/#\"> <img src=\"images/home-small.png\" class=\"small\" alt=\"HOME\"/> <img src=\"images/home.png\" class=\"big\" alt=\"HOME\"/> <span class=\"title\">Home</span> </a> </li> <li> <a href=\"javascript:alert()\"> <img src=\"images/tutorials-small.png\" class=\"small\" alt=\"TUTORIALS\"/> <img src=\"images/tutorials.png\" class=\"big\" alt=\"TUTORIALS\"/> <span class=\"title\">Tutorials</span> </a> </li> </ul>"; document.write(content); } </script>'; ... echo ' <body> <noscript class="ERROR">Please enable JavaScript</noscript> <div id="main"> ' . $menu . ' </div> </body> '; HELP! Quote Link to comment Share on other sites More sharing options...
trq Posted March 24, 2010 Share Posted March 24, 2010 Again. PHP executes on the server while Javascript executes on the client. Hence, assigning a php variable to the output of some Javascript will not work. If you really need this data available to you server side you will need to use Ajax and have Javascript send this data back to the server once it has executed. Quote Link to comment Share on other sites More sharing options...
Joshua4550 Posted March 24, 2010 Author Share Posted March 24, 2010 Again. PHP executes on the server while Javascript executes on the client. Hence, assigning a php variable to the output of some Javascript will not work. If you really need this data available to you server side you will need to use Ajax and have Javascript send this data back to the server once it has executed. Therefore my script should execute the javascript script when it echos the string that contains the script, and then javascript should echo (document.write()) the infomation i wanted. This is not working , because with my script it just doesnt echo anything, but with the script that priti posted, it echos. Please explain what's wrong with my code. $menu = '<script type="text/javascript"> if (!FlashDetect.versionAtLeast() { // Dont have flash 8 or later var content = "<b><font color=#FF0000>HOME, TUTORIALS<br /> Install flash 8 or later to view the proper navigation toolbar! </font></b>"; document.write(content); } else { var content = "<ul id=\"menu\" class=\"menu\"> <li> <a href=\"/#\"> <img src=\"images/home-small.png\" class=\"small\" alt=\"HOME\"/> <img src=\"images/home.png\" class=\"big\" alt=\"HOME\"/> <span class=\"title\">Home</span> </a> </li> <li> <a href=\"javascript:alert()\"> <img src=\"images/tutorials-small.png\" class=\"small\" alt=\"TUTORIALS\"/> <img src=\"images/tutorials.png\" class=\"big\" alt=\"TUTORIALS\"/> <span class=\"title\">Tutorials</span> </a> </li> </ul>"; document.write(content); } </script>'; ... echo ' <body> <noscript class="ERROR">Please enable JavaScript</noscript> <div id="main"> ' . $menu . ' </div> </body> '; Quote Link to comment Share on other sites More sharing options...
trq Posted March 24, 2010 Share Posted March 24, 2010 What does you html source end up looking like in your browser? Quote Link to comment Share on other sites More sharing options...
Joshua4550 Posted March 24, 2010 Author Share Posted March 24, 2010 <div id="main"> <script type="text/javascript"> if (!FlashDetect.versionAtLeast() { // Dont have flash 8 or later var content = "<b><font color=#FF0000>HOME, TUTORIALS<br /> Install flash 8 or later to view the proper navigation toolbar! </font></b>"; document.write(content); } else { var content = "<ul id=\"menu\" class=\"menu\"> <li> <a href=\"/#\"> <img src=\"images/home-small.png\" class=\"small\" alt=\"HOME\"/> <img src=\"images/home.png\" class=\"big\" alt=\"HOME\"/> <span class=\"title\">Home</span> </a> </li> <li> <a href=\"javascript:alert()\"> <img src=\"images/tutorials-small.png\" class=\"small\" alt=\"TUTORIALS\"/> <img src=\"images/tutorials.png\" class=\"big\" alt=\"TUTORIALS\"/> <span class=\"title\">Tutorials</span> </a> </li> </ul>"; document.write(content); } </script> </div> This would all be fine, but it still doesnt actually echo anything on the page. Quote Link to comment Share on other sites More sharing options...
trq Posted March 24, 2010 Share Posted March 24, 2010 I would try wrapping all that code within a self executing function, its obviously not being executed. (function () { // your js goes here })(); Quote Link to comment Share on other sites More sharing options...
trq Posted March 24, 2010 Share Posted March 24, 2010 Have you included the code for the FlashDetect object into your page? Quote Link to comment Share on other sites More sharing options...
Joshua4550 Posted March 24, 2010 Author Share Posted March 24, 2010 Well the code posted by priti earlier works, using the same flash detection function, so I cant see how that'd make it not work. And I used the function, still nothin'... <script type="text/javascript"> (function() { if (!FlashDetect.versionAtLeast() { // Dont have flash 8 or later var content = "<b><font color=#FF0000>HOME, TUTORIALS<br /> Install flash 8 or later to view the proper navigation toolbar! </font></b>"; document.write(content); } else { var content = "<ul id=\"menu\" class=\"menu\"> <li> <a href=\"/#\"> <img src=\"images/home-small.png\" class=\"small\" alt=\"HOME\"/> <img src=\"images/home.png\" class=\"big\" alt=\"HOME\"/> <span class=\"title\">Home</span> </a> </li> <li> <a href=\"javascript:alert()\"> <img src=\"images/tutorials-small.png\" class=\"small\" alt=\"TUTORIALS\"/> <img src=\"images/tutorials.png\" class=\"big\" alt=\"TUTORIALS\"/> <span class=\"title\">Tutorials</span> </a> </li> </ul>"; document.write(content); } }) () </script> Quote Link to comment Share on other sites More sharing options...
Joshua4550 Posted March 24, 2010 Author Share Posted March 24, 2010 No replies now it was moved to Javascript section Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.