views:

116

answers:

2

I was wondering if it would be possible to use jquery to change all object tags on a site automatically to iframe for IE 8 and below. I would like this so that it can be xhtml 1.1 valid and not have to be double coded all the time and you would not have to focus on non-standard browsers.

The data attribute would have to be changed to src, I would like frameborder="0" to be inserted, and all styles set to the object tag also set to the iframe tag.

I don't want this to turn into a debate on iframes vs objects, I just thing this would be a huge time saver and would encourage proper strict xhtml coding.

Thanks for any input!

+1  A: 

For a basic rundown on how to change an element's type see jQuery convert DOM element to different type (no idea whether it'll work properly in XHTML, but it well might), but I don't think this is a good idea at all. I can see it cause delays on older machines (on which IE6 runs), and obviously, it won't work when JavaScript is disabled. All that to achieve valid code? Not a good idea IMO.

Before doing that, if the code has to be valid under any circumstances, I'd consider serving different code to IE6 on server side.

Pekka
For what I am doing a lack of JavaScript support isn't an issue.Plus I've found that the odds of having a device without JavaScript is very rare now. All new phones in the last few years support JavaScript and most people don't keep a phone for more than 2 years.I'll check out the link you sent me, thank you.
geckomist
+1  A: 

I do not know if you can change the DOM element type, but you can always create a new IFRAME element and delete the old element instead.

Something like (caution: untested!)

$("object").each(
    function()
    {
        var obj = $(this);
        $("<iframe/>")
            .attr({
                src: obj.attr("data"),
                style: obj.attr("style"),
                frameborder: 0
            })
            .after(obj);
         obj.remove();
    });
ignaZ
I'm having trouble testing your code. It is not placing the created iframe after the object. So after the object is removed there is nothing left.
geckomist
Should be fixed now.
ignaZ