2010年12月27日 星期一

用 JavaScript 開新視窗的方式

僅列出我常用的方法而已


在開新視窗上,常用兩種方式:


1. window.open ( 開新視窗與原視窗平行處理或顯示額外資訊 )



window.open('[URL]', '[WindowName]', 'status=no,toolbar=no,scrollbars=yes,resizable=yes,width=600,Height=500');


2. window.showModalDialog ( 強迫新視窗處理完成後再回原視窗 )



lRets=window.showModalDialog('[URL]', '[WindowName]', 'dialogWidth:600px;dialogHeight:400px;center:yes;status:no;scrollbars:no');
if(typeof(lRets)=='string')
{
// code ...
}


若是原視窗要接續新視窗回 Call 的 Function,有一個通吃的方式



if (window.dialogArguments != null) {
window.dialogArguments.[FunctionName](varData);
} else if (top.window.opener != null) {
top.window.opener.[FunctionName](varData);
top.window.close();
}