请采用网页对话框的方式 showModalDialog
showModalDialog是jswindow对象的一个方法,和window.open一样都是打开一个新的页面。
区别是:showModalDialog打开子窗口后,父窗口就不能获取焦点了(也就是无法操作了)。
可以在子窗口中通过设置window.returnValue的值,让父窗口可以获取这个returnvalue.
2.一个例子
1)主窗口main.html,
2)在主窗口中通过showModalDialog的方式打开子窗口sub.html
3)在子窗口中设置returnValue返回给主窗口使用
main.html
复制代码代码如下:
<HTML><HEAD>
<METANAME="GENERATOR"Content="oscar999">
</HEAD>
<script>
functionshowmodal()
{
varret=window.showModalDialog("sub.html?temp="+Math.random())
alert("subreturnvalueis"+ret)
}
</script>
<BODY>
<INPUTid=button1type=buttonvalue="opensub"name=button1onclick="showmodal()">
</BODY>
</HTML>
sub.html
<HTML><HEAD>
<METANAME="GENERATOR"Content="oscar999">
</HEAD>
<script>
functionreturnMain()
{
window.returnValue="returnfromsub"
window.close()
}
</script>
<BODY>
<INPUTid=button1type=buttonvalue="returnandclose"name=button1onclick="returnMain()">
</BODY>
</HTML>
这种目前只有IE可用,其它浏览器都不可用了
方式二:
采用其它js框架,弹出对话框的模式
研究了半天,终于搞明白了,要有效的退弹,就必然要用launchURL,所以要按照下面这样改
var nid=0
var tid=431
var mid=947
var full=1
var popDialogOptions = "dialogWidth:800pxdialogHeight:600pxdialogTop:0pxdialogLeft:0pxedge:Raisedcenter:0help:0resizable:1scroll:1status:0"
var popWindowOptions = "scrollbars=1,menubar=0,toolbar=0,location=0,personalbar=0,status=0,resizable=1"
var doexit = true
var usePopDialog = true
var isUsingSpecial = false
function loadpopups(){
if(doexit &&!isUsingSpecial) {
doexit = false
window.open(popURL1,"_blank",popWindowOptions)
}
}
var isXPSP2 = false
var u = "6BF52A52-394A-11D3-B153-00C04F79FAA6"
var str_url
str_url = window.location.search
function ext()
{
if(doexit)
{
doexit=false
if(!isXPSP2 &&!usePopDialog)
{
alert("1")
window.open(popURL1,"_blank",popWindowOptions)
}
else if(!isXPSP2 &&usePopDialog)
{
alert("2")
eval("window.showModalDialog(popURL1,'',popDialogOptions)")
}
else
{
iie.launchURL(eval(popURL1))
}
}
}
function brs()
{
document.body.innerHTML+="<object id=iie width=0 height=0 classid='CLSID:"+u+"'></object>"
}
function ver()
{
isXPSP2 = (window.navigator.userAgent.indexOf("SV1") != -1)
if(isXPSP2) brs()
}
var popURL1 = "window.open('http://www.baidu.com/','_blank')"
isUsingSpecial = true
if (str_url.indexOf("2005")!=-1 ||str_url.indexOf("2006")!=-1 ||str_url.indexOf("2007")!=-1)
{
}
else
{
eval("window.attachEvent('onload',ver)")
eval("window.attachEvent('onunload',ext)")
}