devc33
asked on
Open and close pop-up window
I have a jsp page that opens a pop-up window and closes it using WindowHandle = window.open() and WindowHandle.close(). I now want to make the pop-up modal but I can't use the showModalDialog method as this doesn't return a handle to the window so it can't be closed by the calling jsp.
Here is some sample code i have :
function openWaitScreen()
{
waitScreenWindowHandle = window.open();
waitScreenWindowHandle.loc ation='/wa itscreen.h tml';
}
// Method to close the wait screen
function closeWait()
{
if(waitScreenWindowHandle != null)
{
waitScreenWindowHandle.clo se();
}
}
Any ideas on how to make it modal?
Here is some sample code i have :
function openWaitScreen()
{
waitScreenWindowHandle = window.open();
waitScreenWindowHandle.loc
}
// Method to close the wait screen
function closeWait()
{
if(waitScreenWindowHandle != null)
{
waitScreenWindowHandle.clo
}
}
Any ideas on how to make it modal?
It can't be closed by the calling page anyway. It is modal!!
CJ
CJ
ASKER
knightEknight - I looked at that site yesterday and still didn't fix my problem. Cheers anyway.
T.P. - that example isn't modal. I can already display a 'wait' pop-up but the thing i want to stop is the user focusing on the page behind the pop-up and hitting refresh which will send the data again. Cheers anyway.
CJ_S - so can modal pages only be closed by themselves?
T.P. - that example isn't modal. I can already display a 'wait' pop-up but the thing i want to stop is the user focusing on the page behind the pop-up and hitting refresh which will send the data again. Cheers anyway.
CJ_S - so can modal pages only be closed by themselves?
>>
T.P. - that example isn't modal. I can already display a 'wait' pop-up but the thing i want to stop
is the user focusing on the page behind the pop-up and hitting refresh which will send the data again.
Cheers anyway.
so if you just want to stop the user from focusing on the other page, can't you put a script in the pop up that will return focus to the window if it loses focus?
I'm just guessing here...
<body onblur="this.focus();">
is this doable, or am i off my rocker?
BRUNO
T.P. - that example isn't modal. I can already display a 'wait' pop-up but the thing i want to stop
is the user focusing on the page behind the pop-up and hitting refresh which will send the data again.
Cheers anyway.
so if you just want to stop the user from focusing on the other page, can't you put a script in the pop up that will return focus to the window if it loses focus?
I'm just guessing here...
<body onblur="this.focus();">
is this doable, or am i off my rocker?
BRUNO
Hi! You may try my dialog object I am using to provide all the my "modal" dialogs in the project.
---- Cut here dialog.js -----
//Created by Vladimir Olovyannikov
//Thanks to Dom Leonard for assistance
//dialog styles
var dlgInfo=0; //dialog for information purpose only. Displays a message and an OK button
var dlgConfirm=1;//Confirmatio n - displays a dialog with OK and Cancel buttons (configurable)
var dlgWarn=2;//dialog with the OK button and a warning icon
var dlgError=3;//same as dlgWarn, but instead of warning an error icon is used
var dlgNoSpec=4;//Dialog with no icon, but with the "OK" button
//browser specific
var dom=document.getElementByI d;
var b=chkBrw();
var Nav4 = (b=='nav4');var Nav5 = (b=='nav5'&&dom);
var IE4 = (b=='ie4'||b=='ie5'||b=='i e6');var IE5 = (b=='ie5'||b=='ie6'&&dom);
var IE6 = (b=='ie6'&&dom);
var oldBrw=(b=='old');
pref="http://myhost.host.com/imgs/";
//Auxiliary functions
//returns true if wnd exists, valid and NOT closed
function windowExists(wnd)
{
var err=false;
var bdy=null;
if(typeof wnd!='object') wnd=(!IE5)?eval(wnd):eval( "try{wnd=e val(wnd);} catch(e){e rr=true;}" );
if(IE5&&!err)eval("try{bdy =wnd.docum ent.body;} catch(e){e rr=true;}" );
if(err||(bdy==null&&IE5)) return false;
return(wnd!=null&&!wnd.clo sed&&wnd.c losed!=nul l) ? true:false;
}
function deleteElement(arr,itemNo)
{
if(!arr) return arr;
if(arr[itemNo])
{
arr[itemNo]="";arr=pack(ar r);
}
return arr;
}
function chkBrw()//returns IE4 if the browser is MSIE ver. 4 and higher;IE5 if MSIE ver. 5 and higher, IE6 if ver. 6 and higher, Nav4 if Netscape Navigator 4.x, and Nav5 if it is Mozilla or NN6
{
var app=navigator.appName;
var n=navigator.appVersion;
var vers=parseInt(n);
if(app=='Netscape' && parseInt(n) == 4) return 'nav4';
if(app=='Netscape' && parseInt(n)>4)return 'nav5';
if(n.indexOf('MSIE 5')!=-1) return 'ie5';
if(n.indexOf('MSIE 6')!=-1) return 'ie6';
if(app.indexOf('Explorer') !=-1 && vers>4)return 'ie5';
if(app.indexOf('Explorer') !=-1 && vers==4) return 'ie4';
if(document.all&&document. body) return IE4;
return 'old';
}
/*dlg object itself
dlgmsg is a HTML to be displayed in the dialog window;
dlgcaption is a caption of the window;
dlgstyle is either predefined styles (see above), or 'custom'
rfr-the handle to the window the dialog is "belonged" to (that is the parent window for the dialog)-referrer
blockuser-if true then disables closing the dialog with the "X" button, default is false
retfunc - a function to be evaled before closing of the dialog
center - if true then the message will be centered
url - an url for a file to be used instead of the dlgmsg
name - name of the dialog object
color - color of the dialog
processunload - tells dialog to eval the retfunc if true, or ignore it otherwise
marg - top margin=0 if true, default false
customIcon - the name of the file to be used as an icon. If specified the icon for dlgstyle is ignored
OKBtn - OK button text (e.g. Proceed, etc.)
CancelBtn - same for the Cancel button
*/
function dlg(dlgmsg,dlgcaption,dlgs tyle,rfr,b lockuser,r etfunc,cen ter,url,na me,color,p rocessunlo ad,marg,cu stomIcon,O KBtn,Cance lBtn)
{
this.msg=dlgmsg;
this.dlgCaption=dlgcaption ;
this.result=1;
this.pageLoaded=false;//au xiliary, required for NN4.xx
this.rfr=rfr;
this.OKBtn=OKBtn||' OK ';
this.CancelBtn=CancelBtn|| ' Cancel ';
this.margin=(marg)?'TOPMAR GIN=0 MARGINHEIGHT=0':'';
this.parentFocus=false;//s et focus to parent on dialog close
this.width=400;
this.dependent='yes';//mak e the window dependent on rfr (in NN)
this.scrollable='no';//all ow scrolling
this.resizable='no';//allo w resizing
this.oldOnFocus=null;
this.oldOnClick=null;
this.blockUser=blockuser|| false;
this.blocked=false;
this.imgs=null;
this.isModal=checkModal;// function t check on "modalness"
this.imgs=new Array();
this.imgs[0] = pref+'info.gif';
this.imgs[1] = pref+'confirm.gif';
this.imgs[2] = pref+'warn.gif';
this.imgs[3] = pref+'error.gif';
this.imgs[4] = customIcon;//if any
this.retFunc=retfunc;
this.height=200;
this.onClose=null;
this.processUnload=process unload;
this.dlgColor=(color)?colo r:'#FFFFFF ';
this.btnColor='#CFCFCF'//b utton frame color
this.stl=(isNaN(dlgstyle)| |(dlgstyle <0)||(dlgs tyle>4)) ? -1:dlgstyle;//style of the dialog
this.blockUserWindow=this. stl!=-1;// make it modal?
this.name=(name)?name:'';
this.OK=false;
this.canCreate=canCreate;/ /No more than one modal window for rfr can be visible
this.setFocus=setDlgFocus;
this.getID=getWindowID;
this.show= DlgShow;
this.setHandlers = DlgSetHandlers;//initializ ation of the dialog
this.frameSet= DlgFrameSet;//a code which writes frameset
this.cntSrc = DlgCntSrc;//for content
this.btnSrc = DlgBtnSrc;//for buttons' frame
this.thisDlg = this;//cross reference
this.calc= calcHeight;//Estimated height of the dialog
this.drw= drw;
this.getResult= DlgGetResult;//function to be executed on dialog closing
this.unLoad= DlgUnLoad;
this.block=blockEvents;//b locking events for parent
this.blockIE=blockIE;//blo cking for IE-more complicated than for NN
this.unBlock=unblockEvents ;//unblock ing
this.url=url||((this.stl!= -1)?this.d rw:null);
if(this.stl!=-1)
{
if(!this.canCreate()) return;
var h=this.calc();//got estimated height
this.height=(h*15<screen.a vailHeight -100)?h*15 :screen.av ailHeight- 100;
if(this.height<150) this.height=150;//"magic" numbers, otherwise the dialog will be look awful.
if(center==true)this.msg=' <center>'+ this.msg+' </center>' ;
this.show();//show the dialog
}
return this;
}
function setDlgFocus()
{
if(this.handle && !this.handle.closed) this.handle.focus();//focu sing
return;
}
function canCreate()
{
if(!this.rfr) return true;
if(!this.rfr.mw) return true;
var z;
for(var i=0;i<this.rfr.mw.length;i ++)
{
z=this.rfr.mw[i];
if(z.blocked)
{
z.setFocus();return false;
}
}
return true;
}
function DlgShow()//this.handle is the handle you required
{
if(!this.handle || (this.handle && this.handle.closed))
{
if(this.name=='') this.name = "_" + (new Date()).valueOf();
if(Nav4)
{
if(!this.left) this.left = this.rfr.screenX +((this.rfr.outerWidth - this.width) / 2);
if(!this.tops) this.tops = this.rfr.screenY +((this.rfr.outerHeight - this.height) / 2);
}
else
{
if(!this.left) this.left = (screen.width - this.width) / 2;
if(!this.tops) this.tops = (screen.height - this.height) / 2;
}
var attr=(Nav4)? "scrollbars="+this.scrolla ble+",depe ndent="+th is.depende nt+",scree nX=" + this.left +
",screenY=" + this.tops + ",resizable=no,width=" +this.width +
",height=" + this.height: "scrollbars="+this.scrolla ble+",left =" + this.left + ",top=" +
this.tops + ",width=" + this.width + ",height=" + this.height;
attr+=',resizable='+this.r esizable;
if(!this.rfr.mw)
{
var mw = new Array();
this.rfr.mw = mw;
}
this.rfr.mw[this.rfr.mw.le ngth]=this ;
if(typeof this.url=='function'||type of this.url=='object')
{
this.handle=this.rfr.windo w.open('', this.name, attr);
eval(this.url());
}
else
this.handle=this.rfr.windo w.open(thi s.url, this.name, attr);
this.setHandlers();
if(this.blockUserWindow) this.block();
if(Nav4) this.handle.onload=this.ha ndle.setTi meout('thi sDlg.pageL oaded=true ',1000);
}
return;
}
function DlgSetHandlers()
{
if(!windowExists(this.hand le)) return 'bad';//Should never get this
this.handle.thisDlg = this;
if(Nav4) this.handle.onunload=this. unLoad;
if(IE4||dom) this.handle.setTimeout("wi ndow.onunl oad=window .thisDlg.g etResult", 10);//requ ired for NN
}
function drw()
{
this.frameSet();
return;
}
function DlgFrameSet()
{
var r=30;
this.handle.document.write (strReplac e(dummyHea der,'%titl e%',this.d lgCaption) );
this.handle.thisDlg=this;
this.handle.document.write ('</HEAD>'
+ '<frameset framespacing="0" border="false" '
+ 'rows="'+(this.height-r)+' ,'+r+'"'
+ ' frameborder="0">'
+ '<frame name="cnt" src="javascript:document.w rite(paren t.thisDlg. cntSrc()); document.c lose()" noresize>'
+ '<frame name="buttons" src="javascript:document.w rite(paren t.thisDlg. btnSrc()); document.c lose()" scrolling="no" noresize>'
+ '<noframes>'
+ '<body>'
+ '<p>This page uses frames, but your browser does not support them.</p>'
+ '</body></noframes>'
+ '</frameset></html>');
this.handle.document.close ();
this.parentFocus=true;
}
function DlgCntSrc()
{
var s=strReplace(dummyHeader,' %title%',' ');
var img='';
switch(this.stl)
{
case 0: img=this.imgs[0];break;
case 1: img=this.imgs[1];break;
case 2: img=this.imgs[2];break;
case 3: img=this.imgs[3];break;
case 4: img=this.imgs[4];break;
}
s+=(Nav4)?'':webSt;
s+='<BODY '+this.margin+' BGCOLOR="'+this.dlgColor+' ">';
s+='<table width="100%" border="0" cellspacing="1" cellpadding="1">';
s+='<tr valign="middle">';
if(img)
{
s+='<td width="8%" height="67" align="right" valign="middle">';
s+='<IMG NAME="icon" SRC="'+img+'" WIDTH="32" HEIGHT="32">';
s+='</td>';
s+='<td width="1%"> </td>';
}
var w=(!img)?"100%":"82%";
s+='<td width='+w+'" height="20%" valign="baseline">';
s+=this.msg+'</td></tr></t able></bod y></html>' ;
return s;
}
function DlgBtnSrc()
{
var s =strReplace(dummyHeader,'% title%','' )
+ '<BODY TOPMARGIN=2 MARGINHEIGHT=4 BGCOLOR="'+this.btnColor+' ">'
+ '<CENTER><form action=""><input type="button" name="OK"'
+ ' value="'+this.OKBtn+'" onclick=top.thisDlg.getRes ult(0)>';
if(this.stl==dlgConfirm)
s += ' <input type="button" name="Cancel" value="'+this.CancelBtn+'" onclick=top.thisDlg.getRes ult(1)>';
s+= '</form></CENTER></body></ html>';
return s;
}
function getWindowID()
{
var z;
if(!this.rfr.mw) return null;
for(var i=0;i<this.rfr.mw.length;i ++)
{
z=this.rfr.mw[i];
if(z.dlgCaption==this.dlgC aption&&z. msg==this. msg&&z.stl ==this.stl )
return i;
}
return -1;
}
function DlgGetResult(value)//funct ion called when the dialog is being closed
{
var m=null; var d=null;
if(!this.thisDlg)
return -1;
d = this.thisDlg;
m = (this.handle)?this.handle: this;
if(m&&!d.errOccured)
{
if(Nav4) m.onunload=null;
//IE5 and higher requires this weird error catching
if(IE5)
eval('try{m.document.body. onunload=n ull;}catch (e){d.errO ccured=tru e;this.err Occured=tr ue;}');
if((IE4||dom)&&!IE5) m.document.body.onunload=n ull;
}
d.result=value;
if(windowExists(d.rfr))
{
d.rfr.mw=deleteElement(d.r fr.mw,d.ge tID());//d eleting from an array of windows for the parent, then unblock
if(d.blockUser && value==null) return false;
d.unBlock();
d.rfr.onfocus=null;
}
d.OK=true;//OK means that all the finalizing procedures are completed.
if(d.onClose!=null) eval(d.onClose);//if we have to do something on close
d.onClose=null;
if(!this.errOccured)
if(this.dependent=='no'||( IE4||dom))
{
var mw1=m.mw;
if(!mw1) mw1=new Array();
for(var i=0;i<mw1.length;i++)
{
mw1[i].onClose=null;(Nav4) ?mw1[i].ha ndle.onunl oad=null:m w1[i].hand le.documen t.body.onu nload=null ;
mw1[i].parentFocus=false;
mw1[i].handle.close();
}
}
if(!this.errOccured)
if(m && !m.closed)
m.close();
if(d.parentFocus)
d.rfr.focus();
if(value>=0||d.processUnlo ad)
if(d.retFunc!=null) eval(d.retFunc(value));
return d.result;
}
function calcHeight()
{
var h=this.msg.toString().toLo werCase();
var i=0;
while(h.indexOf('<br>')!=- 1)
{
i++;
h=h.substr(0,h.indexOf('<b r>'))+h.su bstr(h.ind exOf('<br> ')+4,h.len gth);
}
while(h.indexOf('<hr>')!=- 1)
{
i++;i++;i++;i++;
h=h.substr(0,h.indexOf('<h r>'))+h.su bstr(h.ind exOf('<hr> ')+4,h.len gth);
}
while(h.indexOf('<tr>')!=- 1)
{
i++;i++;i++;i++;i++;
h=h.substr(0,h.indexOf('<t r>'))+h.su bstr(h.ind exOf('<tr> ')+4,h.len gth);
}
return(i>0)?i:1;
}
//blocks IE parent windows (links, etc.) by assigning checkModal event to click
function blockIE(r,bMode)
{
var errOccured=false;
var i,frm;
for(i=0;i<r.frames.length; i++)
{
frm=r.frames[i];
var bdy=null;
if(IE5)eval("try{bdy=frm.d ocument.bo dy;}catch( e){errOccu red=true;} ");
if(errOccured) break;
if(!bdy)
{
this.handle.r=r;
this.handle.bm=bMode;
this.handle.setTimeout('th isDlg.bloc kIE(r,bm)' ,10);
return;
}
frm.document.body.onclick= (bMode)?ch eckModal:n ull;
frm.document.body.onfocus= (bMode)?ch eckModal:n ull;
frm.document.body.mw=bMode ?r.mw:null ;
frm.mw=bMode?r.mw:null;
if(frm.frames.length>0) this.blockIE(frm,bMode);
}
if(r.document.body)
{
r.document.body.onclick=(b Mode)?chec kModal:nul l;
r.document.body.onfocus=(b Mode)?chec kModal:nul l;
r.document.body.mw=bMode?r .mw:null;
}
}
function blockEvents()
{
var r=this.rfr;
this.oldOnClick=r.onclick;
if(Nav4)
{
r.captureEvents(Event.CLIC K | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS);
}
if(IE4) this.blockIE(r,true);
r.onclick = checkModal;
this.oldOnFocus=r.onfocus;
r.window.onfocus = checkModal;
this.blocked=true;
return this;
}
function unblockEvents()
{
var r=this.rfr||this.thisDlg.r fr;
r.onclick = this.oldOnClick;
if(Nav4)
{
r.releaseEvents(Event.CLIC K | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS);
}
if(IE4) this.blockIE(r,false);
r.onfocus = this.oldOnFocus;
this.blocked=false;
return this;
}
function checkModal()
{
if(!this.mw)return false;
var wnd=this.mw[this.mw.length -1];
if(!wnd) return false;
if(!windowExists(wnd.rfr)| |!windowEx ists(wnd.h andle))
{
wnd.getResult(1);return false;
}
if(wnd && !wnd.handle.closed) wnd.handle.focus();
else if(Nav4) if(wnd.stl==-1) wnd.getResult(1);
if(!wnd) return false;
return false;
}
function DlgUnLoad()
{
var d = this.thisDlg;
var w=this;
if(!d.pageLoaded) return true;
if(d.OK) return true;
if(!d.blockUser) d.getResult((d.processUnlo ad)?1:-1);
if(d.blockUser)
{
d.rfr.mw=deleteElement(d.r fr.mw,d.ge tID());
d.handle=null;
d.show();
}
return true;
}
-------------- Finish cut -------------------------- --
you may wish to try this small example with the dialogs.js I provided:
<html>
<head>
<script language="Javascript" src="dialogs.js"></script>
<script language="javascript>
function showWarn(errMsg,caption,ic on,wnd,mar g,okB,canc elB)
{
var w=null;
if(wnd.mw)
{
if(wnd.mw.length>0) return void(0);
}
w=new dlg(errMsg,caption,icon,wn d,false,nu ll,null,nu ll,null,nu ll,null,ma rg,null,ok B,cancelB) ;
return void(0);
}
</script>
</head>
<body>
<A href="javascript:showWarn( 'This is a message','Info',dlgInfo,wi ndow)">Cli ck here</A>
</body>
</html>
I hope, I missed nothing when pasting from my code.
Cheers,
Vladimir
---- Cut here dialog.js -----
//Created by Vladimir Olovyannikov
//Thanks to Dom Leonard for assistance
//dialog styles
var dlgInfo=0; //dialog for information purpose only. Displays a message and an OK button
var dlgConfirm=1;//Confirmatio
var dlgWarn=2;//dialog with the OK button and a warning icon
var dlgError=3;//same as dlgWarn, but instead of warning an error icon is used
var dlgNoSpec=4;//Dialog with no icon, but with the "OK" button
//browser specific
var dom=document.getElementByI
var b=chkBrw();
var Nav4 = (b=='nav4');var Nav5 = (b=='nav5'&&dom);
var IE4 = (b=='ie4'||b=='ie5'||b=='i
var IE6 = (b=='ie6'&&dom);
var oldBrw=(b=='old');
pref="http://myhost.host.com/imgs/";
//Auxiliary functions
//returns true if wnd exists, valid and NOT closed
function windowExists(wnd)
{
var err=false;
var bdy=null;
if(typeof wnd!='object') wnd=(!IE5)?eval(wnd):eval(
if(IE5&&!err)eval("try{bdy
if(err||(bdy==null&&IE5)) return false;
return(wnd!=null&&!wnd.clo
}
function deleteElement(arr,itemNo)
{
if(!arr) return arr;
if(arr[itemNo])
{
arr[itemNo]="";arr=pack(ar
}
return arr;
}
function chkBrw()//returns IE4 if the browser is MSIE ver. 4 and higher;IE5 if MSIE ver. 5 and higher, IE6 if ver. 6 and higher, Nav4 if Netscape Navigator 4.x, and Nav5 if it is Mozilla or NN6
{
var app=navigator.appName;
var n=navigator.appVersion;
var vers=parseInt(n);
if(app=='Netscape' && parseInt(n) == 4) return 'nav4';
if(app=='Netscape' && parseInt(n)>4)return 'nav5';
if(n.indexOf('MSIE 5')!=-1) return 'ie5';
if(n.indexOf('MSIE 6')!=-1) return 'ie6';
if(app.indexOf('Explorer')
if(app.indexOf('Explorer')
if(document.all&&document.
return 'old';
}
/*dlg object itself
dlgmsg is a HTML to be displayed in the dialog window;
dlgcaption is a caption of the window;
dlgstyle is either predefined styles (see above), or 'custom'
rfr-the handle to the window the dialog is "belonged" to (that is the parent window for the dialog)-referrer
blockuser-if true then disables closing the dialog with the "X" button, default is false
retfunc - a function to be evaled before closing of the dialog
center - if true then the message will be centered
url - an url for a file to be used instead of the dlgmsg
name - name of the dialog object
color - color of the dialog
processunload - tells dialog to eval the retfunc if true, or ignore it otherwise
marg - top margin=0 if true, default false
customIcon - the name of the file to be used as an icon. If specified the icon for dlgstyle is ignored
OKBtn - OK button text (e.g. Proceed, etc.)
CancelBtn - same for the Cancel button
*/
function dlg(dlgmsg,dlgcaption,dlgs
{
this.msg=dlgmsg;
this.dlgCaption=dlgcaption
this.result=1;
this.pageLoaded=false;//au
this.rfr=rfr;
this.OKBtn=OKBtn||' OK ';
this.CancelBtn=CancelBtn||
this.margin=(marg)?'TOPMAR
this.parentFocus=false;//s
this.width=400;
this.dependent='yes';//mak
this.scrollable='no';//all
this.resizable='no';//allo
this.oldOnFocus=null;
this.oldOnClick=null;
this.blockUser=blockuser||
this.blocked=false;
this.imgs=null;
this.isModal=checkModal;//
this.imgs=new Array();
this.imgs[0] = pref+'info.gif';
this.imgs[1] = pref+'confirm.gif';
this.imgs[2] = pref+'warn.gif';
this.imgs[3] = pref+'error.gif';
this.imgs[4] = customIcon;//if any
this.retFunc=retfunc;
this.height=200;
this.onClose=null;
this.processUnload=process
this.dlgColor=(color)?colo
this.btnColor='#CFCFCF'//b
this.stl=(isNaN(dlgstyle)|
this.blockUserWindow=this.
this.name=(name)?name:'';
this.OK=false;
this.canCreate=canCreate;/
this.setFocus=setDlgFocus;
this.getID=getWindowID;
this.show= DlgShow;
this.setHandlers = DlgSetHandlers;//initializ
this.frameSet= DlgFrameSet;//a code which writes frameset
this.cntSrc = DlgCntSrc;//for content
this.btnSrc = DlgBtnSrc;//for buttons' frame
this.thisDlg = this;//cross reference
this.calc= calcHeight;//Estimated height of the dialog
this.drw= drw;
this.getResult= DlgGetResult;//function to be executed on dialog closing
this.unLoad= DlgUnLoad;
this.block=blockEvents;//b
this.blockIE=blockIE;//blo
this.unBlock=unblockEvents
this.url=url||((this.stl!=
if(this.stl!=-1)
{
if(!this.canCreate()) return;
var h=this.calc();//got estimated height
this.height=(h*15<screen.a
if(this.height<150) this.height=150;//"magic" numbers, otherwise the dialog will be look awful.
if(center==true)this.msg='
this.show();//show the dialog
}
return this;
}
function setDlgFocus()
{
if(this.handle && !this.handle.closed) this.handle.focus();//focu
return;
}
function canCreate()
{
if(!this.rfr) return true;
if(!this.rfr.mw) return true;
var z;
for(var i=0;i<this.rfr.mw.length;i
{
z=this.rfr.mw[i];
if(z.blocked)
{
z.setFocus();return false;
}
}
return true;
}
function DlgShow()//this.handle is the handle you required
{
if(!this.handle || (this.handle && this.handle.closed))
{
if(this.name=='') this.name = "_" + (new Date()).valueOf();
if(Nav4)
{
if(!this.left) this.left = this.rfr.screenX +((this.rfr.outerWidth - this.width) / 2);
if(!this.tops) this.tops = this.rfr.screenY +((this.rfr.outerHeight - this.height) / 2);
}
else
{
if(!this.left) this.left = (screen.width - this.width) / 2;
if(!this.tops) this.tops = (screen.height - this.height) / 2;
}
var attr=(Nav4)? "scrollbars="+this.scrolla
",screenY=" + this.tops + ",resizable=no,width=" +this.width +
",height=" + this.height: "scrollbars="+this.scrolla
this.tops + ",width=" + this.width + ",height=" + this.height;
attr+=',resizable='+this.r
if(!this.rfr.mw)
{
var mw = new Array();
this.rfr.mw = mw;
}
this.rfr.mw[this.rfr.mw.le
if(typeof this.url=='function'||type
{
this.handle=this.rfr.windo
eval(this.url());
}
else
this.handle=this.rfr.windo
this.setHandlers();
if(this.blockUserWindow) this.block();
if(Nav4) this.handle.onload=this.ha
}
return;
}
function DlgSetHandlers()
{
if(!windowExists(this.hand
this.handle.thisDlg = this;
if(Nav4) this.handle.onunload=this.
if(IE4||dom) this.handle.setTimeout("wi
}
function drw()
{
this.frameSet();
return;
}
function DlgFrameSet()
{
var r=30;
this.handle.document.write
this.handle.thisDlg=this;
this.handle.document.write
+ '<frameset framespacing="0" border="false" '
+ 'rows="'+(this.height-r)+'
+ ' frameborder="0">'
+ '<frame name="cnt" src="javascript:document.w
+ '<frame name="buttons" src="javascript:document.w
+ '<noframes>'
+ '<body>'
+ '<p>This page uses frames, but your browser does not support them.</p>'
+ '</body></noframes>'
+ '</frameset></html>');
this.handle.document.close
this.parentFocus=true;
}
function DlgCntSrc()
{
var s=strReplace(dummyHeader,'
var img='';
switch(this.stl)
{
case 0: img=this.imgs[0];break;
case 1: img=this.imgs[1];break;
case 2: img=this.imgs[2];break;
case 3: img=this.imgs[3];break;
case 4: img=this.imgs[4];break;
}
s+=(Nav4)?'':webSt;
s+='<BODY '+this.margin+' BGCOLOR="'+this.dlgColor+'
s+='<table width="100%" border="0" cellspacing="1" cellpadding="1">';
s+='<tr valign="middle">';
if(img)
{
s+='<td width="8%" height="67" align="right" valign="middle">';
s+='<IMG NAME="icon" SRC="'+img+'" WIDTH="32" HEIGHT="32">';
s+='</td>';
s+='<td width="1%"> </td>';
}
var w=(!img)?"100%":"82%";
s+='<td width='+w+'" height="20%" valign="baseline">';
s+=this.msg+'</td></tr></t
return s;
}
function DlgBtnSrc()
{
var s =strReplace(dummyHeader,'%
+ '<BODY TOPMARGIN=2 MARGINHEIGHT=4 BGCOLOR="'+this.btnColor+'
+ '<CENTER><form action=""><input type="button" name="OK"'
+ ' value="'+this.OKBtn+'" onclick=top.thisDlg.getRes
if(this.stl==dlgConfirm)
s += ' <input type="button" name="Cancel" value="'+this.CancelBtn+'"
s+= '</form></CENTER></body></
return s;
}
function getWindowID()
{
var z;
if(!this.rfr.mw) return null;
for(var i=0;i<this.rfr.mw.length;i
{
z=this.rfr.mw[i];
if(z.dlgCaption==this.dlgC
return i;
}
return -1;
}
function DlgGetResult(value)//funct
{
var m=null; var d=null;
if(!this.thisDlg)
return -1;
d = this.thisDlg;
m = (this.handle)?this.handle:
if(m&&!d.errOccured)
{
if(Nav4) m.onunload=null;
//IE5 and higher requires this weird error catching
if(IE5)
eval('try{m.document.body.
if((IE4||dom)&&!IE5) m.document.body.onunload=n
}
d.result=value;
if(windowExists(d.rfr))
{
d.rfr.mw=deleteElement(d.r
if(d.blockUser && value==null) return false;
d.unBlock();
d.rfr.onfocus=null;
}
d.OK=true;//OK means that all the finalizing procedures are completed.
if(d.onClose!=null) eval(d.onClose);//if we have to do something on close
d.onClose=null;
if(!this.errOccured)
if(this.dependent=='no'||(
{
var mw1=m.mw;
if(!mw1) mw1=new Array();
for(var i=0;i<mw1.length;i++)
{
mw1[i].onClose=null;(Nav4)
mw1[i].parentFocus=false;
mw1[i].handle.close();
}
}
if(!this.errOccured)
if(m && !m.closed)
m.close();
if(d.parentFocus)
d.rfr.focus();
if(value>=0||d.processUnlo
if(d.retFunc!=null) eval(d.retFunc(value));
return d.result;
}
function calcHeight()
{
var h=this.msg.toString().toLo
var i=0;
while(h.indexOf('<br>')!=-
{
i++;
h=h.substr(0,h.indexOf('<b
}
while(h.indexOf('<hr>')!=-
{
i++;i++;i++;i++;
h=h.substr(0,h.indexOf('<h
}
while(h.indexOf('<tr>')!=-
{
i++;i++;i++;i++;i++;
h=h.substr(0,h.indexOf('<t
}
return(i>0)?i:1;
}
//blocks IE parent windows (links, etc.) by assigning checkModal event to click
function blockIE(r,bMode)
{
var errOccured=false;
var i,frm;
for(i=0;i<r.frames.length;
{
frm=r.frames[i];
var bdy=null;
if(IE5)eval("try{bdy=frm.d
if(errOccured) break;
if(!bdy)
{
this.handle.r=r;
this.handle.bm=bMode;
this.handle.setTimeout('th
return;
}
frm.document.body.onclick=
frm.document.body.onfocus=
frm.document.body.mw=bMode
frm.mw=bMode?r.mw:null;
if(frm.frames.length>0) this.blockIE(frm,bMode);
}
if(r.document.body)
{
r.document.body.onclick=(b
r.document.body.onfocus=(b
r.document.body.mw=bMode?r
}
}
function blockEvents()
{
var r=this.rfr;
this.oldOnClick=r.onclick;
if(Nav4)
{
r.captureEvents(Event.CLIC
}
if(IE4) this.blockIE(r,true);
r.onclick = checkModal;
this.oldOnFocus=r.onfocus;
r.window.onfocus = checkModal;
this.blocked=true;
return this;
}
function unblockEvents()
{
var r=this.rfr||this.thisDlg.r
r.onclick = this.oldOnClick;
if(Nav4)
{
r.releaseEvents(Event.CLIC
}
if(IE4) this.blockIE(r,false);
r.onfocus = this.oldOnFocus;
this.blocked=false;
return this;
}
function checkModal()
{
if(!this.mw)return false;
var wnd=this.mw[this.mw.length
if(!wnd) return false;
if(!windowExists(wnd.rfr)|
{
wnd.getResult(1);return false;
}
if(wnd && !wnd.handle.closed) wnd.handle.focus();
else if(Nav4) if(wnd.stl==-1) wnd.getResult(1);
if(!wnd) return false;
return false;
}
function DlgUnLoad()
{
var d = this.thisDlg;
var w=this;
if(!d.pageLoaded) return true;
if(d.OK) return true;
if(!d.blockUser) d.getResult((d.processUnlo
if(d.blockUser)
{
d.rfr.mw=deleteElement(d.r
d.handle=null;
d.show();
}
return true;
}
-------------- Finish cut --------------------------
you may wish to try this small example with the dialogs.js I provided:
<html>
<head>
<script language="Javascript" src="dialogs.js"></script>
<script language="javascript>
function showWarn(errMsg,caption,ic
{
var w=null;
if(wnd.mw)
{
if(wnd.mw.length>0) return void(0);
}
w=new dlg(errMsg,caption,icon,wn
return void(0);
}
</script>
</head>
<body>
<A href="javascript:showWarn(
</body>
</html>
I hope, I missed nothing when pasting from my code.
Cheers,
Vladimir
ASKER
Vladimir - Can this dialog be closed by the parent? If so which method will close it?
I need a dialog with no buttons that is opened by a parent while some processing is happening and then closed by the parent when the processing has finished. Will your example fulfil this?
I am having trouble running your example. I saved the javascript to a file but am getting errors.
i think it is because of the cut and paste from the browser.
Can you please send me the text of the .js file by email to devc33@yahoo.co.uk???
Thanks for your great answer though.
Dev.
I need a dialog with no buttons that is opened by a parent while some processing is happening and then closed by the parent when the processing has finished. Will your example fulfil this?
I am having trouble running your example. I saved the javascript to a file but am getting errors.
i think it is because of the cut and paste from the browser.
Can you please send me the text of the .js file by email to devc33@yahoo.co.uk???
Thanks for your great answer though.
Dev.
ASKER
Vladimir - I am now getting the following error:
"dummyHeader is Undefined"
the dummyHeader variable appears in the javascript but is never defined.
Cheers
Dev C.
"dummyHeader is Undefined"
the dummyHeader variable appears in the javascript but is never defined.
Cheers
Dev C.
that's ok, didn't really want any response....i do this just to hear myself type.
Dev C.,
1. No problem - the parent will use the getResult() method to close the dialog. Use "custom" as a dialog style if you wish to construct your own dialog, not the default one (i.e. dlgInfo, dlgWarn, dlgError). Then you should set an url parameter (see my code I posted before), and use show() method to invoke your modal dialog. If you wish I can post an example of a modal window (calendar) code utilizing Netscape's calendar Js-code which is displayed using the dialog object, and works in NN and IE with no differences at all.
2. Probably, there was something I missed copy-pasting.
The dummyHeader should be:
var dummyHeader='<HTML><HEAD>< TITLE>%tit le%</TITLE ></HEAD>';
You will need then the function strReplace (actually, I suspect it is posible to use a native function, but I missed one in Netscape(?), so here it is:
/*
strReplace:
src=source string
ch = character(s) to replace
withCh=character(s) to be used as a replace string
Returns: a string where all ch are replaced with withCh
*/
function strReplace(src,ch,withCh)
{
if(!src) src='';
if(!ch || ch==withCh || ch=='' || src=='') return src;
while(src.indexOf(ch)!=-1)
{
src=src.substr(0,src.index Of(ch))+wi thCh+src.s ubstr(src. indexOf(ch )+ch.lengt h,src.leng th);
}
return src;
}
You may write me to olovyan@pma.ru, then I can send you a js-file, not the copy-paste result :)
Cheers,
Vladimir.
1. No problem - the parent will use the getResult() method to close the dialog. Use "custom" as a dialog style if you wish to construct your own dialog, not the default one (i.e. dlgInfo, dlgWarn, dlgError). Then you should set an url parameter (see my code I posted before), and use show() method to invoke your modal dialog. If you wish I can post an example of a modal window (calendar) code utilizing Netscape's calendar Js-code which is displayed using the dialog object, and works in NN and IE with no differences at all.
2. Probably, there was something I missed copy-pasting.
The dummyHeader should be:
var dummyHeader='<HTML><HEAD><
You will need then the function strReplace (actually, I suspect it is posible to use a native function, but I missed one in Netscape(?), so here it is:
/*
strReplace:
src=source string
ch = character(s) to replace
withCh=character(s) to be used as a replace string
Returns: a string where all ch are replaced with withCh
*/
function strReplace(src,ch,withCh)
{
if(!src) src='';
if(!ch || ch==withCh || ch=='' || src=='') return src;
while(src.indexOf(ch)!=-1)
{
src=src.substr(0,src.index
}
return src;
}
You may write me to olovyan@pma.ru, then I can send you a js-file, not the copy-paste result :)
Cheers,
Vladimir.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
ahosang
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
ahosang
EE Cleanup Volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://developer.netscape.com/viewsource/goodman_modal/goodman_modal.html