0

I am trying to use a Flash detection script to assess whether Flash Plugin is enabled in the user browser so that a different page loads. The Flash detection script is as follows, using jquery 1.8.2 and jquery.jqplugin 1.0.2

<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="jquery.jqplugin.1.0.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $("#withflash").hide();
    $("#noflash").hide();
    if ($.browser.flash == true)
      $("#withflash").show ();
    else
      $("#noflash").show ();
});
</script>
<div id="withflash">Flash Supported</div>
<div id="noflash">Flash Not Supported</div>

I get the display that "Flash Supported" if Flash Plugin is present.. I need to capture the value whether flash plugin value is true in a php variable $hasFlashSupport as below:

<?php
echo " $hasFlashSupport";
exit;
?>

I am aware that PHP is server based and Javascript is client based.. Hence Ajax would be a nice option to capture the javascript variable to my php variable. I am totally ignorant about Ajax syntax and how to achieve it.

Request the experts here to help me out with the code on how this can be achieved... Thanking all of you in advance..

4
  • 4
    Please read stackoverflow.com/editing-help#code to learn how to format code properly. Since you are using jQuery, I would recommend to start by reading api.jquery.com/jQuery.ajax. This MDN and Wikipedia article might also be helpful to get a general understanding of Ajax. Commented Oct 30, 2012 at 4:53
  • On a side note, you're going to get a nasty Flash of Unstyled Content (FUOC) with that code; both divs will be displayed until all content is loaded and the javascript runs. Hide both divs with CSS then you can just show the appropriate one once you do the flash detection. As for sending it to PHP, why do you need to? What are you planning to do with it? Commented Oct 30, 2012 at 4:56
  • @shels but why are you echoing var as string. Commented Oct 30, 2012 at 5:06
  • You can't get JavaScript data into PHP variables. PHP creates the page, sends the result to the client, and THEN JavaScript runs on the client. In order for a PHP script to get information from JavaScript, it has to load a new page or use AJAX to send a request back to the server (but that will be a different script). Commented Oct 30, 2012 at 6:12

2 Answers 2

0

You can do that using DOMDocument object that have a getElementById method.

2
  • I am not echoing var as string...$hasFlashSupport is a php variable. If flash plugin is true $hasFlashSupport = "true"...Need to capture whether flash plugin is true from Javascript tp my php variable using ajax.. I am a ajax newbie and some written code would be fine :) Commented Oct 30, 2012 at 5:17
  • The google code in this link is also good. code.google.com/p/doctype-mirror/wiki/… There is no function to call; the code is executed as soon as the script is executed, and the results are always available in the goog.userAgent.flash.HAS_FLASH and goog.userAgent.flash.VERSION variables. but how to transfer goog.userAgent.flash.HAS_FLASH from code in the link to php variable ??? Commented Oct 30, 2012 at 6:11
0

Try this:

if true

<div id="withflash">
    <?php echo '$hasFlashSupport'; ?>
</div>

else

<div id="noflash">
    <?php echo '$hasFlashSupport'; ?>
</div>
1
  • if what is true ???? That is the issue. How can i transfer the true value from Javascript to php. I need Ajax code to transfer javascript "true" value to php variable... Commented Oct 30, 2012 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.