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