Tip: Click lines to highlight, hold ctrl/cmd to multi-select
z-index fix for internet explorer (11-Feb @ 15:47)
Fixes the z-index bug in ie6 where so called "windowed" elements (select, object, etc) dont respect z-index in relation to "non-windowed" elements.
Syntax Highlighted Code
- <script type="text/javascript">
- // make the specified div a windowed control in IE6
- // this masks an iframe (which is a windowed control) onto the div,
- // turning the div into a windowed control itself
- function makeWindowed(p_div)
- {
- var is_ie6 =
- document.all &&
- (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1);
- if (is_ie6)
- {
- var html =
- "<iframe style=\"position: absolute; display: block; " +
- "z-index: -1; width: 100%; height: 100%; top: 0; left: 0;" +
- "filter: mask(); background-color: #ffffff; \"></iframe>";
- if (p_div) p_div.innerHTML += html;
- // force refresh of div
- var olddisplay = p_div.style.display;
- p_div.style.display = 'none';
- p_div.style.display = olddisplay;
- };
- }
- </script>
- </head>
- <div id="test" style="position: absolute; z-index: 2;
- top: 50; left: 30; width: 200px; height: 200px;
- background-color: red">
-
- </div>
- <select style="position: absolute; z-index: 1; top: 50;">
- <option>test</option>
- </select>
- <a href="javascript:makeWindowed(document.getElementById('test'));">
- Make Windowed</a>
- </body>
- </html>
Plain Code
<html>
<head>
<script type="text/javascript">
// make the specified div a windowed control in IE6
// this masks an iframe (which is a windowed control) onto the div,
// turning the div into a windowed control itself
function makeWindowed(p_div)
{
var is_ie6 =
document.all &&
(navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1);
if (is_ie6)
{
var html =
"<iframe style=\"position: absolute; display: block; " +
"z-index: -1; width: 100%; height: 100%; top: 0; left: 0;" +
"filter: mask(); background-color: #ffffff; \"></iframe>";
if (p_div) p_div.innerHTML += html;
// force refresh of div
var olddisplay = p_div.style.display;
p_div.style.display = 'none';
p_div.style.display = olddisplay;
};
}
</script>
</head>
<body>
<div id="test" style="position: absolute; z-index: 2;
top: 50; left: 30; width: 200px; height: 200px;
background-color: red">
</div>
<select style="position: absolute; z-index: 1; top: 50;">
<option>test</option>
</select>
<a href="javascript:makeWindowed(document.getElementById('test'));">
Make Windowed</a>
</body>
</html>