Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-02-03 16:30:47

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

[solved] Flash detection and variables

I’m using swfobject to detect whether Flash is installed to a browser. Like this:

<script src="//cdnjs.cloudflare.com/ajax/libs/swfobject/2.2/swfobject.min.js"></script>

<script type="text/javascript">
if(swfobject.hasFlashPlayerVersion("1"))
{
    document.write("<txp:variable name='flash_status' value='1' />");
    document.write("<!-- <txp:variable name='flash_status' /> -->");
}
else
{
    document.write("<txp:variable name='flash_status' value='0' />");
    document.write("<!-- <txp:variable name='flash_status' /> -->");
}
</script>

This works. In my iOS 7 simulator (no Flash available), I see <!-- 0 -->; in my Flash-enabled browser I see <!-- 1 -->, implying the variable has been set correctly in both instance. All good, so far.

In an article form, I’m using variable to populate a span, like this:

<span><txp:variable name="flash_status" /><span>

My workflow is that I expect to see 0 if Flash is not installed, and 1 if it is. In each case, I see 0.

The only instances of flash_status in the page are in the script block as shown above. The only instance of flash_status in the article form is the span block as shown above – i.e., there are no cases where the flash_status variable is set to 0 outside of the code listed.

I am very new to JavaScript, and I think my single and double quotes are nested correctly; the conflict seems to be when the variable check is performed from within the form rather than the page. I’d be grateful for any indicators as to where I’ve gone wrong. Thank you in advance.

Last edited by gaekwad (2014-02-04 10:11:17)

Offline

#2 2014-02-03 17:20:11

etc
Developer
Registered: 2010-11-11
Posts: 5,393
Website GitHub

Re: [solved] Flash detection and variables

Hi Pete,

the quotes are ok, but not the rest :) The last value of <txp:variable name="flash_status" /> available to txp (that knows nothing about js) is 0, and what is sent to the client (browser) is:

<script type="text/javascript">
if(swfobject.hasFlashPlayerVersion("1"))
{
    document.write("");
    document.write("<!-- 1 -->");
}
else
{
    document.write("");
    document.write("<!-- 0 -->");
}
</script>

You can do it all in js:

<script type="text/javascript">
var flashEnabled = swfobject.hasFlashPlayerVersion("1") ? 1 : 0;
</script>

<span><script>document.write(flashEnabled);</script></span>

Offline

#3 2014-02-03 17:24:07

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

Re: [solved] Flash detection and variables

Oh, actually that does make sense – it also explains why the tag trace was not what I was expecting, too.

Merci beaucoup, captain!

Offline

Board footer

Powered by FluxBB