Cleverly uses the layer in DHTML to overwrite window controls in IE

Source: Internet
Author: User

It was about 1 year ago that coalesys released the first webmenu 2.0 Beta. At that time we began demonstrating a technique for overlaying your wed controls in Internet Explorer.

In case you don't already know, too wed controls in IE will always cover DHTML layers. that means if you have a div that pops up or floats on the page and it intersects with a pair wed control (such as the Common select box), the pair wed control will obscure the DIV, no matter what zindex you have set for each element. more information is available in this Microsoft KB article.

The initial solution adopted by most developers who cared about such things (including ourselves) was to dynamically hide controls wed controls when it was necessary to display the DIV over them. far from being a perfect solution, it was better than the alternative of doing nothing at all.

It did have one very frustrating aspect. people who evaluated webmenu didn't understand why their select boxes wowould disappear. and we are talking much more than just ASP. NET developers, as we produce webmenu for ASP, as well as general web development. it seemed like every day we have Ed a support question, "I found a bug in webmenu. the Select boxes are disappearing ". and although we did provide the ability to turn the feature off, nobody really bothered once they understood the nature of the issue.

Then, as luck wowould have it, a developer called who wanted to use our product for it's broad set of features, but who absolutely needed to have the menu appear over some pretty wed objects. what was unique about his call was that he had the idea for a solution and shared it with us. while we didn't use the full scope of his idea, we were able to take from it what we needed to cover against wed controls in IE 5.5. so, enough yacking. you probably surfed here to read about the solution. and here it is:

IFRAME

The IFRAME control has a unique nature in Internet Explorer 5.5. it can exist in both the zindex of your wed controls and the zindex of regular HTML elements. simply put, you can Shim an IFRAME under your Div. the IFRAME will block out the specified wed control.

Set up your IFRAME:

<IFRAME Style = "display: none; left: 0px; position: absolute; top: 0px" src = "javascript: false; "frameborder =" 0 "scrolling =" no "> </iframe>

The src attribute is set with a useless JavaScript statement so that the IFRAME does not try to load a page (which you won't notice it doing, but it will be the cause for tripping the "Unsecured items" message if you use it on a HTTPS page ).

You can code your IFRAME as a static element on the page, or if you are going to be using more than one of them you may want to dynamically create them as required. the insertadjacenthtml () method is good for that.

Now, all that is needed is to size the IFRAME according to the dimensions of your Div, position it, place it one layer beneath the DIV in the zindex order and make it "visible ". the IFRAME's style object will allow you to do these tasks:

IFRAME. style. Top
IFRAME. style. Left
IFRAME. style. Width
IFRAME. style. Height
IFRAME. style. zindex
IFRAME. style. Display

What about transparency?

If the DIV has transparent areas, you'll want those areas to punch through the IFRAME to the page background. there are two ways you can make an IFRAME transparent. the one that works for this situation is to set the style object's filter property:

IFRAME. style. Filter = 'progid: DXImageTransform. Microsoft. Alpha (style = 0, opacity = 0 )';

This in effect makes the entire IFRAME transparent, but it will still block out the specified wed controls. the other technique, which uses the IFRAME element's allowtransparency attribute, actually pertains to making the interior page background of the IFRAME transparent, so that any content inside the IFRAME can have transparency. however, this mode changes the nature of the IFRAME and it no longer serves our purpose for blocking out when wed controls.

What about ie versions prior to 5.5?

The IFRAME's unique nature surfaced only in Internet Explorer 5.5. prior to this, iframes where straight has wed controls themselves. that means they cocould get abve other incluwed controls, but no HTML element (like the Div) cocould be seen abve them. there is a solution, but it involves a lot of effort to get working. you can dynamically write the content of your Div into the IFRAME itself, get it sized appropriately based on the dimensions of the original Div, and then just move it around und as your absolutely positioned element. there are a couple of caveats:

1. the IFRAME, like any frame, has it's own JavaScript environment. if you want DHTML actions in the IFRAME to integrate with the JavaScript Functions in your main page, you will have to bridge the gap between the two JavaScript environments.

2. mouse events, such as onmouseout and onmouseover, can be called out of logical order when the mouse moves between frames in IE 4 and 5. this problem is compounded when you are using timers and need to precisely control their execution and cancellation via mouse events.

Our original webmenu 2.0 Beta used this technique successfully for IE 4 and 5, but in looking forward to adding new features to the product, we cocould see that this solution "over-worked the plumbing" to a great extent. the "shim" technique compatible only with IE 5.5 had zero limit tural impact and was chosen for this reason. you can still hide against wed elements in earlier browsers as an acceptable solution.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.