XHTML 1.1 OBJECT tag fix for IE7 and IE8

<- Back To Blog

Published: 01/02/2013 UTC

Updated: 01/02/2013 UTC

Recently I upgraded one of my projects to XHTML1.1 Strict, perhaps because I am a fan of XML I quite like XHTML Strict. One issue I came across is that iframes have been deprecated. This makes it difficult to use things such as Google Maps and Recaptcha. After searching the web I found a great article by Pop Labs (Pop Labs is no more) which came with a javascript solution. This did not quite work for me, so I decided to write my own using jQuery.

Html

<!--[if lte IE 8]>
<script type="text/javascript" src="/scripts/xhtmlFix.js"></script>
<![endif]-->

The above HTML code makes the script only run on IE7 and IE8.

jQuery(document).ready(function(){
    /**
    * Replace each object with iframe.
    * Licensed under MIT licence (http://opensource.org/licenses/MIT)
    * Copyright (c) 2013 Jeremy Sells
    */
    if(jQuery("object").lenght > 0) {
        jQuery("object").each(function(){
            var frame = jQuery("<iframe src='"+jQuery(this).attr("data")+"' class='"+jQuery(this).attr("class")+"' id='"+jQuery(this).attr("id")+"'/>");
            jQuery(this).replaceWith(frame);
        });
    }
});

The above jQuery code see how many <object> tabs there are on the page and replaces each one with a <object> tag. It swaps the <object>'s data for <iframe> src and keeps the css class's and id, which keeps the height and width.

Licensed under MIT licence (http://opensource.org/licenses/MIT)

<- Back To Blog

The opinions expressed on this website are my own and do not necessarily reflect the views of my employer. The posts on this website are provided "as is" with no warranties and confer no rights

Copyright © 2025 Jeremy Sells - See Site Terms/Disclaimer