Re-coding EMBED so that it pass the W3C validation

My site has the following code it. On running the W3C Markup Validation Service I received a whole host of errors pertaining to this code. On further research I discovered that its because I can’t use embed in XHTML 1.0 Transitional files.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="<?php echo($width); ?>" height="<?php echo($height); ?>">
<param name="movie" value="<?php echo JURI::root(); ?>/modules/mod_shoutcastplayer/ffmp3-config.swf" />
<param name="flashvars" value="url=<?php echo($url); ?>/?lang=auto&amp;codec=<?php echo $codec; ?>&amp;volume=<?php echo $volume; ?>&amp;introurl=<?php echo($introurl); ?><?php if($autostart == 'true'){echo('&amp;autoplay=');echo $autostart;}else if (autostart == 'false'){echo('');};?>&amp;tracking=true&amp;jsevents=false&amp;buffering=5&amp;skin=<?php echo JURI::root(); ?>/modules/mod_shoutcastplayer/<?php echo($skin); ?>.xml&amp;title=<?php echo($name); ?>" />
<param name="wmode" value="transparent" />
<param name="allowscriptaccess" value="always" />
<param name="scale" value="noscale" />
<embed src="<?php echo JURI::root(); ?>modules/mod_shoutcastplayer/ffmp3-config.swf" flashvars="url=<?php echo($url); ?>/?lang=auto&amp;codec=<?php echo $codec; ?>&amp;volume=<?php echo $volume; ?>&amp;introurl=<?php echo($introurl); ?><?php if($autostart == 'true'){echo('&autoplay='); echo $autostart;} else if (autostart == 'false'){echo('');};?>&amp;tracking=true&amp;jsevents=false&amp;buffering=5&amp;skin=<?php echo JURI::root(); ?>/modules/mod_shoutcastplayer/<?php echo($skin); ?>.xml&amp;title=<?php echo($name); ?>" width="<?php echo($width); ?>" scale="noscale" height="<?php echo($height); ?>" wmode="transparent" allowscriptaccess="always" type="application/x-shockwave-flash" />
</object>

http://www.alistapart.com/articles/byebyeembed/ and [URL=“http://stackoverflow.com/questions/4962859/how-to-make-html-embed-code-from-youtube-w3c-compliant”]http://stackoverflow.com/questions/4962859/how-to-make-html-embed-code-from-youtube-w3c-compliant appear to provide the solution but I can’t seem to get the coding right.

While the original code in question works, I would like it to pass the validation test.

There’s too much PHP in that code to get a really good look at what you are working with. Can you post the code as it outputs to the browser? (That is, by going to View > Source.)

The fact that <embed> doesn’t validate is not a biggie, really, as all browsers support it anyway. Validation is more a way of checking for any serious errors.

Yeah I know… just don’t like the fact that they are there :slight_smile:

<!-- Start Radio Player -->
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="46" width="191">
<param name="movie" value="http://pilgrimpassingthrough.internetlinked.com//modules/mod_shoutcastplayer/ffmp3-config.swf">
<param name="flashvars" value="url=http://sc2.shoutcaststreaming.us:8000/?lang=auto&amp;codec=mp3&amp;volume=30&amp;introurl=&amp;tracking=true&amp;jsevents=false&amp;buffering=5&amp;skin=http://pilgrimpassingthrough.internetlinked.com//modules/mod_shoutcastplayer/ffmp3-compact.xml&amp;title=B.A.R.">
<param name="wmode" value="transparent">
<param name="allowscriptaccess" value="always">
<param name="scale" value="noscale">
<embed src="http://pilgrimpassingthrough.internetlinked.com/modules/mod_shoutcastplayer/ffmp3-config.swf" flashvars="url=http://sc2.shoutcaststreaming.us:8000/?lang=auto&amp;codec=mp3&amp;volume=30&amp;introurl=&amp;tracking=true&amp;jsevents=false&amp;buffering=5&amp;skin=http://pilgrimpassingthrough.internetlinked.com//modules/mod_shoutcastplayer/ffmp3-compact.xml&amp;title=B.A.R." scale="noscale" wmode="transparent" allowscriptaccess="always" type="application/x-shockwave-flash" height="46" width="191">
</object>
<!-- End Radio Player-->

Get rid of the classid attribute from the <object> tag. That will stop the object tag working for IE6 but will allow it to work for all other browsers so that the <embed> tag will then never be referenced and can be removed.

If you have oone of the rare sites that still have visitors who use IE6 then you can use IE conditional comments and two object tags (one with the classid for IE6 and one without for all other browsers) so as to not need any embed tags.

The only browser that doesn’t recognise the standard object tag without the classid and which would therefore run the embed version if you got rid of the classid and left the rest of the code alone is IE6.

Awesome… I have got it to partially work

<!-- Start Radio Player -->
<object  width="<?php echo($width); ?>" height="<?php echo($height); ?>">
<param name="movie" value="<?php echo JURI::root(); ?>/modules/mod_shoutcastplayer/ffmp3-config.swf" />
<param name="flashvars" value="url=<?php echo($url); ?>/?lang=auto&amp;codec=<?php echo $codec; ?>&amp;volume=<?php echo $volume; ?>&amp;introurl=<?php echo($introurl); ?><?php if($autostart == 'true'){echo('&amp;autoplay=');echo $autostart;}else if (autostart == 'false'){echo('');};?>&amp;tracking=true&amp;jsevents=false&amp;buffering=5&amp;skin=<?php echo JURI::root(); ?>/modules/mod_shoutcastplayer/<?php echo($skin); ?>.xml&amp;title=<?php echo($name); ?>" />
<param name="wmode" value="transparent" />
<param name="allowscriptaccess" value="always" />
<param name="scale" value="noscale" />
<!--[if IE6]><embed src="<?php echo JURI::root(); ?>modules/mod_shoutcastplayer/ffmp3-config.swf" flashvars="url=<?php echo($url); ?>/?lang=auto&amp;codec=<?php echo $codec; ?>&amp;volume=<?php echo $volume; ?>&amp;introurl=<?php echo($introurl); ?><?php if($autostart == 'true'){echo('&autoplay='); echo $autostart;} else if (autostart == 'false'){echo('');};?>&amp;tracking=true&amp;jsevents=false&amp;buffering=5&amp;skin=<?php echo JURI::root(); ?>/modules/mod_shoutcastplayer/<?php echo($skin); ?>.xml&amp;title=<?php echo($name); ?>" width="<?php echo($width); ?>" scale="noscale" height="<?php echo($height); ?>" wmode="transparent" allowscriptaccess="always" type="application/x-shockwave-flash" /><![endif]-->
</object>

When I try add the following I get errors again

<!--[if !IE6]><object  width="<?php echo($width); ?>" height="<?php echo($height); ?>"><![endif]-->
<!--[if IE6]><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="<?php echo($width); ?>" height="<?php echo($height); ?>"><![endif]-->

The logic feels sound but obviously it’s not

<object <!--[if IE6]>classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"<![endif]--> width="<?php echo($width); ?>" height="<?php echo($height); ?>">

Try that instead.

Non-IE browsers just see the IE conditional tags as HTML comments.

Keep in mind that IE6 usage has fallen by the wayside, so it might not even be necessary to cater to it (unless your visitor demographic indicates otherwise).

Yes I tried that but the W3C validation then failed again. I agree, I am happy to just ignore IE6 but am interested from a purely academic point of view as to how I would solve this. What is interesting is the the conditional tag works just fine lower down in the code.

In #6 it will fail Validation because you cannot have comment delimiters within a tag itself; <p <!-- I am invalid –> >Error!</p> also occurring; <foo<bar> is invalid in HTML you’d have to use the conditional outside of the tag.

Within #5 it looks like you haven’t closed those new OBJECT elements though I would need to see the full parsed code sample including those nested OBJECT preferably after the PHP processor has dealt with the echo and outputted the markup with the variables.

Don’t mean to jump in so late but why don’t you simply use the SWFObject library?

You could easily construct the array data needed to build the <object> element plus you don’t have to worry about the W3C validator as the object won’t be embed until the page completely loads.

Try this:

  1. Use HTML5.
  2. Use only embed.

Here is the original code:

<object <!--[if IE6]>classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"<![endif]--> width="<?php echo($width); ?>" height="<?php echo($height); ?>">
<param name="movie" value="<?php echo JURI::root(); ?>/modules/mod_shoutcastplayer/ffmp3-config.swf" />
<param name="flashvars" value="url=<?php echo($url); ?>/?lang=auto&amp;codec=<?php echo $codec; ?>&amp;volume=<?php echo $volume; ?>&amp;introurl=<?php echo($introurl); ?><?php if($autostart == 'true'){echo('&amp;autoplay=');echo $autostart;}else if (autostart == 'false'){echo('');};?>&amp;tracking=true&amp;jsevents=false&amp;buffering=5&amp;skin=<?php echo JURI::root(); ?>/modules/mod_shoutcastplayer/<?php echo($skin); ?>.xml&amp;title=<?php echo($name); ?>" />
<param name="wmode" value="transparent" />
<param name="allowscriptaccess" value="always" />
<param name="scale" value="noscale" />
<!--[if IE6]><embed src="<?php echo JURI::root(); ?>modules/mod_shoutcastplayer/ffmp3-config.swf" flashvars="url=<?php echo($url); ?>/?lang=auto&amp;codec=<?php echo $codec; ?>&amp;volume=<?php echo $volume; ?>&amp;introurl=<?php echo($introurl); ?><?php if($autostart == 'true'){echo('&autoplay='); echo $autostart;} else if (autostart == 'false'){echo('');};?>&amp;tracking=true&amp;jsevents=false&amp;buffering=5&amp;skin=<?php echo JURI::root(); ?>/modules/mod_shoutcastplayer/<?php echo($skin); ?>.xml&amp;title=<?php echo($name); ?>" width="<?php echo($width); ?>" scale="noscale" height="<?php echo($height); ?>" wmode="transparent" allowscriptaccess="always" type="application/x-shockwave-flash" /><![endif]-->
</object>

And here is the passed code:

<!-- Start Radio Player -->
<object <!--[if IE6]>classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"<![endif]--> width="191" height="46">
<param name="movie" value="http://pilgrimpassingthrough.internetlinked.com//modules/mod_shoutcastplayer/ffmp3-config.swf" />
<param name="flashvars" value="url=http://sc2.shoutcaststreaming.us:8000/?lang=auto&amp;codec=mp3&amp;volume=30&amp;introurl=&amp;tracking=true&amp;jsevents=false&amp;buffering=5&amp;skin=http://pilgrimpassingthrough.internetlinked.com//modules/mod_shoutcastplayer/ffmp3-compact.xml&amp;title=B.A.R." />
<param name="wmode" value="transparent" />
<param name="allowscriptaccess" value="always" />
<param name="scale" value="noscale" />
<!--[if IE6]><embed src="http://pilgrimpassingthrough.internetlinked.com/modules/mod_shoutcastplayer/ffmp3-config.swf" flashvars="url=http://sc2.shoutcaststreaming.us:8000/?lang=auto&amp;codec=mp3&amp;volume=30&amp;introurl=&amp;tracking=true&amp;jsevents=false&amp;buffering=5&amp;skin=http://pilgrimpassingthrough.internetlinked.com//modules/mod_shoutcastplayer/ffmp3-compact.xml&amp;title=B.A.R." width="191" scale="noscale" height="46" wmode="transparent" allowscriptaccess="always" type="application/x-shockwave-flash" /><![endif]-->
</object>
<!-- End Radio Player-->

Don’t mean to jump in so late but why don’t you simply use the SWFObject library?

Sorry by I don’t understand what you mean… what I am doing is editing a Joomla plugin so try and correct the code… basically looking at the code and googling solutions; Don’t know what the SWFObject library is or how to use it… that said, it gives me something new to google :slight_smile: Thanks

See how the following goes for you, I simply converted your current code to work with the SWFObject library but of course you will need to test it. Before you can test it make sure you download the swfobject.js file from this link and ensure you update the src path in the below script tag to the location on the server.

<span id="swfMovie"></span>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
    var settings = {
        // Path to the SWF file we want to use
        movie      : <?php echo "'" . JURI::root() . "/modules/mod_shoutcastplayer/ffmp3-config.swf'"; ?>,

        // The height and width of the flash file
        height     : parseInt(<?php echo "'$height'"; ?>),
        width      : parseInt(<?php echo "'$width'"; ?>),

        // Setup the flashvars
        flashvars  : {
            autoplay    : <?php echo ($autostart === 'true') ? "'true'" : "''"; ?>,
            buffering   : 5,
            codec       : <?php echo "'$codec'"; ?>,
            introurl    : <?php echo "'$introurl'"; ?>,
            jsevents    : false,
            lang        : 'auto',
            skin        : <?php echo "'" . JURI::root() . "/modules/mod_shoutcastplayer/" . $skin . ".xml'"; ?>,
            title       : <?php echo "'$name'"; ?>,
            tracking    : true,
            url         : <?php echo "'$url'"; ?>,
            volume      : <?php echo "'$volume'"; ?>
        },

        // Setup the parameters
        params     : {
            allowscriptaccess : 'always',
            flashvars         : settings.flashvars,
            movie             : settings.movie,
            scale             : 'noscale',
            wmode             : 'transparent'
        },

        // Setup the attributes
        attributes : {}
    };

    swfobject.embedSWF(settings.movie, 'swfMovie', settings.width, settings.height, false, settings.flashvars, settings.params, settings.attributes);
</script>