/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Writing Alternate Flash Content in JS from PHP Include

I need help with a JS function that was generated by Flash CS3. I am trying to output alternate content in HTML using a combination of JavaScript and PHP. The <noscript> portion of the code works, but the Flash version detection JS doesn’t work properly.

[B]The original output for non-flash is as follows:[/B]

[code]
} else { // flash is too old or we can’t detect the plugin
var alternateContent = ‘Alternate HTML content should be placed here.’
+ ‘This content requires the Adobe Flash Player.’
+ ‘<a href=http://www.macromedia.com/go/getflash/>Get Flash</a>’;
document.write(alternateContent); // insert non-flash content
}
}
// –>
</script>
<noscript>
// Provide alternate content for browsers that do not support scripting
// or for those that have scripting disabled.
Alternate HTML content should be placed here. This content requires the Adobe Flash Player.
<a href=”http://www.macromedia.com/go/getflash/”>Get Flash</a>
</noscript>
[/code]

[B]I’ve modified the code to look something like this:[/B]

[code]
} else { // flash is too old or we can’t detect the plugin
var alternateContent = ‘<?php echo file_get_contents(‘/web/content/news-noflash.php’); ?>’
document.write(alternateContent); // insert non-flash content
}
}
// –>
</script>
<noscript>
<?php # Load the content
@include(‘/web/content/news-noflash.php’);
?>
</noscript>
[/code]

[B]In this example, I would get the following output in the source:

[/B]

[code]
} else { // flash is too old or we can’t detect the plugin

var alternateContent = ‘
<h2>What’s New</h2>
<p><a href=”/blog/”>Go to News</a></p>
<p><strong>NOTE:</strong> This is where our Flash News feed loads. We are making an XML / HTML feed to load in the event you don’t support Flash and Javascript. We apologize for the inconvenience.</p>document.write(alternateContent); // insert non-flash content
}
}
// –>
</script>
<noscript>
<h2>What’s New</h2>
<p><a href=”/blog/”>Go to News</a></p>
<p><strong>NOTE:</strong> This is where our Flash News feed loads. We are making an XML / HTML feed to load in the event you don’t support Flash and Javascript. We apologize for the inconvenience.</p></noscript>[/code]

[B]In the browser, the Flash won’t appear at all. [/B]I assume that the apostrophes and semi-colon used in the PHP expression are interferring with the JS. Is there any way I can circumvent this?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 20.2007 — The var alternateContent must be on 1 line or split: var alternateContent = ''+
'&lt;h2&gt;What's New&lt;/h2&gt;'+
'&lt;p&gt;&lt;a href="/blog/"&gt;Go to News&lt;/a&gt;&lt;/p&gt;'+
'&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; This is where our Flash News feed loads. We are making an XML / HTML feed to load in the event you don't support Flash and Javascript. We apologize for the inconvenience.&lt;/p&gt;';
document.write(alternateContent); // insert non-flash content

Note the use of extra backslashes
Copy linkTweet thisAlerts:
@abovethefoldauthorSep 20.2007 — The var alternateContent must be on 1 line or split: var alternateContent = ''+
'&lt;h2&gt;What's New&lt;/h2&gt;'+
'&lt;p&gt;&lt;a href="/blog/"&gt;Go to News&lt;/a&gt;&lt;/p&gt;'+
'&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; This is where our Flash News feed loads. We are making an XML / HTML feed to load in the event you don't support Flash and Javascript. We apologize for the inconvenience.&lt;/p&gt;';
document.write(alternateContent); // insert non-flash content
Note the use of extra backslashes[/quote]


Fang, Thanks for the speedy reply. There's one caveat that I forgot to mention in my problem - I prefer not to write the JavaScript string containing the content; I want to load the content from an existing file using PHP. More specifically, the content you quoted exists in the news-noflash.php. I would prefer to keep the content separated from the logic for sake of portability.

With all that being said, should I be using some combination of escape, htmlentities and similar functions in PHP along with JS to achieve this end-goal?

Thanks again for your response!
Copy linkTweet thisAlerts:
@FangSep 21.2007 — If you want it in a JavaScript variable you have to output it on 1 line or as shown.
Copy linkTweet thisAlerts:
@abovethefoldauthorSep 25.2007 — Fang, I took the contents of the include file and removed all the line breaks. This allowed me to successfully import the content with my JS document.write statement and PHP include statement.

[CODE]document.write('<?php @include("filename.php"); ?>');[/CODE]

Thanks for your help!
×

Success!

Help @abovethefold spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...