Have you ever run into a depth problem with drop-down menus in Internet Explorer, everybody's favorite browser
"chuckle"? If you have ever built a drop-down menu then I am sure that you have had this issue and it is not an easy issue to work around, until now...
If you have had this issue in the past you have probably found developers using the iframe hack, which renders an invisible iframe below the drop-down menu and brings it to the highest depth level, even above select lists in forms! This is a great solution, although, the solutions that I have found have been elaborate and complicated to implement. Therefore, I have created the method below named addIframe, which simply takes two parameters and renders the iframe for you, allowing much more flexibility from a development standpoint.
function addIframe(id, el)
{
if(document.getElementById(id) == null)
{
var _iframe = document.createElement("iframe");
_iframe.src = 'about:blank';
_iframe.scrolling = 'no';
_iframe.frameborder = '0';
_iframe.id = id;
_iframe.name = id;
_iframe.style.position = 'absolute';
if(el)
{
document.getElementById(el).appendChild(_iframe);
}
else
{
document.body.appendChild(_iframe);
}
}
return document.getElementById(id);
}
The method takes two parameters, the first is a unique id for the iframe that you will be creating. This allows you to later reference the iframe by id in order to move it, resize it, etc. The second parameter is a optional parameter which expects an element id for any element in which you want to append the iframe to, if this parameter does not exist it is simply appended to the document body. After the iframe is created it will be returned and can then be manipulated as I mentioned earlier. This is where you will want to tell it where to go and what size to be. Enjoy...
Labels: javascript