PDA

View Full Version : Simple Issue I can't seem to resolve..


A_Grant
11-25-2009, 02:04 AM
I have this simple script that uses and if then statement. The point of this is to show one video player for an iphone and a flash player for everything else. I am using the "document.write" function for writing the embed codes, but the quotes close the function. I tried using /" before every quote and it didn't work for me. I also tried wrapping the embed function in a single quote..that did not work either.

I don't know a lot about javascript, but would love to have this script..

Please help! I hate to be a beggar but I can't seem to find my solution online.

Here is the code


<script type="text/javascript">
<!--
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
{
document.write("iPhone embed code here");
}

else
{
document.write("<embed src='player.swf' width='470' height='290' bgcolor='#ffffff' allowscriptaccess='always' allowfullscreen='true' flashvars='file=bunny.flv&streamer=rtmp://edge01.fms.dutchview.nl/botr' />");
}

-->
</script>

Epotus
11-30-2009, 04:39 PM
A_Grant,

The code you provided worked for me using IE 6 and Chrome 3, however I did notice some problems.

First, where in your page are you placing the script tag? This may be a silly question, but make sure it’s inside the <BODY> tag of your page.

Second, I would remove the html comments from within the script tag <!-- --> these have not been needed since Netscape Navigator 2.0

Finally I would use a single quote to wrap in your write() function, and use the standard double quotes for all the HTML attributes.

I have never used the userAgent property, so I cannot comment if that is the best practice for identifying and iPhone or iPod. Typically people check for browser by object detection not a properties value.


OLD CODE:

<script type="text/javascript">
<!--
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
{
document.write("iPhone embed code here");
}

else
{
document.write("<embed src='player.swf' width='470' height='290' bgcolor='#ffffff' allowscriptaccess='always' allowfullscreen='true' flashvars='file=bunny.flv&streamer=rtmp://edge01.fms.dutchview.nl/botr' />");
}

-->
</script>


NEW CODE:

<body>
<script type="text/javascript">

if ( (navigator.userAgent.match(/iPhone/i) ) || (navigator.userAgent.match(/iPod/i) ) )
{
document.write('iPhone embed code here');
}
else
{
document.write('<embed src="player.swf" width="470" height="290" bgcolor="#ffffff" allowscriptaccess="always" allowfullscreen="true" flashvars="file=bunny.flv&streamer=rtmp://edge01.fms.dutchview.nl/botr" />');
}

</script>
</body>

Philip M
11-30-2009, 07:06 PM
I do not see anything wrong with your code (although the <!-- and //--> comment (hiding) tags have not been necessary since IE3).