Concept of creating a modal window in html is follows
For IE6 select element over absolute div problem, iframe of same size as of masking div is created and placed in between masking div and body element.
Javascript function to create a modal window by masking body in HTML
var maskpanel=function()
{
this.divobj;
this.show=function()
{
if(!document.getElementById("xdivmasking"))
{
var divEle=document.createElement('div');
divEle.setAttribute("id","xdivmasking");
document.body.appendChild(divEle);
var divSty=document.getElementById("xdivmasking").style;
divSty.position="absolute"; divSty.top="0px"; divSty.left="0px";
divSty.zIndex="46"; divSty.opacity=".50";divSty.backgroundColor="#000";
divSty.filter="alpha(opacity=50)";
var divFram=document.createElement('iframe');
divFram.setAttribute("id","xmaskframe");
document.body.appendChild(divFram);
divSty=document.getElementById("xmaskframe").style;
divSty.position="absolute"; divSty.top="0px"; divSty.left="0px";
divSty.zIndex="45";divSty.border="none";divSty.filter="alpha(opacity=0)";
}
this.divobj=document.getElementById("xdivmasking");
this.waitifrm=document.getElementById("xmaskframe");
var dsh=document.documentElement.scrollHeight;
var dch=document.documentElement.clientHeight;
var dsw=document.documentElement.scrollWidth;
var dcw=document.documentElement.clientWidth;
var bdh=(dsh>dch)?dsh:dch;
var bdw=(dsw>dcw)?dsw:dcw;
this.waitifrm.style.height=this.divobj.style.height=bdh+'px';
this.waitifrm.style.width=this.divobj.style.width=bdw+'px';
this.waitifrm.style.display=this.divobj.style.display="block";
};
this.hide=function()
{
this.waitifrm.style.display=this.divobj.style.display="none";
};
}
"maskpanel" function to be placed between the "script" in body of HTML.
"maskpanel" function can be used asdivmask=new maskpanel(); divmask.show();After using maskpanel can be closed as
divmask.hide();
View Demo of "maskpanel" Javascript function to create a modal window by masking body in HTML.
I like the simplicity of this - no special effects, just a mask and a content div.
this is very good. Thanks.
this is very good. Thanks.
The best I have seen! Congratulations!
It certainly looks very elegant. Out of curiosity I tested the code and I found that it works just fine even without calling the show() and hide() method on the javascript object. That is showing and hiding the "demodiv" div alone seems to works just as well. What did I miss? Thanks.
perfect solution to create model window I have seen ever before. Thanks a lot.
Much the simplest example I've found, and works on IE6! Thanks.
To echo comments above, this is by far and away the simplest and yet most complete example of a modal DIV - thank you for taking the time to write and to publish it. There are countless alternatives but 99% of these seem to require heavyweight, lazy boy Javascript libraries to achieve the same effect.
Yes, really very good many thanks
This is great but it needs a tweak for pages on IE that adjust in height through AJAX and such (new height can only be found through document.body.scrollHeight): var bodSW = document.body.scrollWidth; var bodSH = document.body.scrollHeight; var docSW = document.documentElement.scrollWidth; var docSH = document.documentElement.scrollHeight; var docCW = document.documentElement.clientWidth; var docCH = document.documentElement.clientHeight; var docSW = (docSW > bodSW) ? docSW : bodSW; var docSH = (docSH > bodSH) ? docSH : bodSH; var maskWidth = (docSW > docCW) ? docSW : docCW; var maskHeight = (docSH > docCH) ? docSH : docCH;
The demo link not works, What mus be writed in html body portion?
this was an awesome help.. I used this Mask panel to prohibit user communication with the menu page while loading other urls...Thanks a lot.
I was having a problem with nesting YUI2 modal dialog boxes. Your code appears to have solved it. I made the YUI dialogs not modal and created my own mask, then carefully showed and hide the mask appropriately. Interestingly enough I was also getting a 'script running slow, do you want to stop it?' pop-up in IE that also appeared to go away once I was no longer nesting YUI2 modals. Thanks!