XHTML 1.1 Object Tag Fix for IE7 and IE8

Recently, I upgraded one of my projects to XHTML 1.1 Strict. I have always liked XML, so XHTML Strict appealed to me. One issue I came across was that iframes had been deprecated. This made it difficult to use services such as Google Maps and reCAPTCHA. After searching the web, I found a useful article by Pop Labs (which is no longer online) that included a JavaScript solution. That approach 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 HTML above makes the script run only on IE7 and IE8.

jQuery(document).ready(function(){
    /**
    * Replace each object with iframe.
    * Licensed under the MIT licence (http://opensource.org/licenses/MIT)
    * Copyright (c) 2013 Jeremy Sells
    */
    if(jQuery("object").length > 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 jQuery above checks how many <object> tags are on the page and replaces each one with an <iframe> tag. It uses the <object> data value as the <iframe> source and keeps the CSS classes and ID, preserving the height and width.

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

Published: 01/02/2013 UTC

Updated: 18/06/2026 UTC

<- 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 © 2026 Jeremy Sells - See Site Terms/Disclaimer