Javascript and "&"
Permalink Browser Info Environment
I've got a little javascript in my detail template that embeds a Flash fallback audio player in case the browser doesn't support the HTML5 audio tag. Code below is copied directly from my detail template (note that my Data Display placeholder tags are there too, ((rID-2}} and {{mp3-2}}).
The problem is that the "&&" part is being rendered as "&&" once the HTML has been rendered, which is keeping the script from doing it's thing. Code below is copied from HTML source.
Is there a way to keep the parser or whatever it is from replacing those "&&" characters?
<script type="text/javascript"> var audioTag = document.createElement('audio'); if (!(!!(audioTag.canPlayType) && ("no" != audioTag.canPlayType("audio/mpeg")) && ("" != audioTag.canPlayType("audio/mpeg")))) { AudioPlayer.embed("audioplayer-{{rID-2}}", {soundFile: "{{mp3-2}}"}); } </script>
The problem is that the "&&" part is being rendered as "&&" once the HTML has been rendered, which is keeping the script from doing it's thing. Code below is copied from HTML source.
<script type="text/javascript"> var audioTag = document.createElement('audio'); if (!(!!(audioTag.canPlayType) && ("no" != audioTag.canPlayType("audio/mpeg")) && ("" != audioTag.canPlayType("audio/mpeg")))) { AudioPlayer.embed("audioplayer-8", {soundFile: "/c5/files/7913/4150/8091/Why_Glory_Days.mp3"}); } </script>
Is there a way to keep the parser or whatever it is from replacing those "&&" characters?
Type: | Discussion |
---|---|
Status: | New |
It appears the forum is parsing the amp HTML character code I put above. *sigh*. && is being parsed as "& amp ;" (minus the spaces) in the rendered HTML. You're probably following me here but I wanted to clarify anyway.
Hahaha. That's funny...I read "&& is being rendered as &&" and I was thinking..."okay so what's the problem."
Yeah, to be honest the quickest fix for this might just be to make it a nested if structure rather than using the ampersand's. So for example:
That's note 100% correct so don't copy and paste. All of you're !'s confused me, so I think I may have changed some of the login. Seems like you should still be able to do it this way though.
Yeah, to be honest the quickest fix for this might just be to make it a nested if structure rather than using the ampersand's. So for example:
<script type="text/javascript"> var audioTag = document.createElement('audio'); if (!(!!(audioTag.canPlayType)) { if("no" != audioTag.canPlayType("audio/mpeg")) { if ("" != audioTag.canPlayType("audio/mpeg")) { AudioPlayer.embed("audioplayer-{{rID-2}}", {soundFile: "{{mp3-2}}"}); } } } </script>
That's note 100% correct so don't copy and paste. All of you're !'s confused me, so I think I may have changed some of the login. Seems like you should still be able to do it this way though.