Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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..

share|improve this question
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. – Felix Kling Oct 30 '12 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? – El Yobo Oct 30 '12 at 4:56
@shels but why are you echoing var as string. – Jai Oct 30 '12 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). – Barmar Oct 30 '12 at 6:12

2 Answers

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

share|improve this answer
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 :) – shels Oct 30 '12 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 ??? – shels Oct 30 '12 at 6:11

Try this:

if true

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

else

<div id="noflash">
    <?php echo '$hasFlashSupport'; ?>
</div>
share|improve this answer
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... – shels Oct 30 '12 at 5:39
Where is your ajax code. – Jai Oct 30 '12 at 5:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.