IE6: Set OBJECT tag width and height dynamically


I had an issue this week with IE6 and the OBJECT tag.  The real issues is supporting IE6, but that’s another battle all together.

I was trying to use percentage based width and height on the OBJECT tag.  In IE6 this always rendered nothing.  IE7 and Firefox worked fine. If I used a fixed width and height for IE6 it worked.

Apparently IE6 did not implement the W3C standard for width and height on the OBJECT tag.

My solution was to use some JavaScript for getting the screen resolution and then calculating the percentage.  It wasn’t what I wanted but it worked.

function SetObjectTagProps(id)
{

    var obj = document.getElementById(id);
    obj.width = (GetWidth() * 0.95);
    obj.height = (GetHeigth() * 0.95);

}

function GetWidth()
{
    var myWidth = 0
    if (typeof (window.innerWidth) == 'number')
    {
        //Non-IE
        myWidth = window.innerWidth;

    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;

    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight))
    {
        //IE 4 compatible
        myWidth = document.body.clientWidth;

    }
    //alert('Width = ' + myWidth);

    return myWidth;
}

function GetHeigth()
{
    myHeight = 0;
    if (typeof (window.innerWidth) == 'number')
    {
        //Non-IE
        myHeight = window.innerHeight;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;

    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight))
    {
        //IE 4 compatible
        myHeight = document.body.clientHeight;

    }

    //alert('Height = ' + myHeight);

    return myHeight;
}
Advertisements

2 Responses to “IE6: Set OBJECT tag width and height dynamically”

  1. Shawn Yale Says:

    Thanks for posting this buddy. I will put a trackback link on my site so its easy to find. I’m glad you found the solution.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: