<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
var win;
function openNew(){
win=window.open();
win.opener.focus();
}
</script>
</head>
<body >
<input type='button' onclick='openNew()' value='弹出窗体'>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
var win;
function openNew(){
if(!win){
win=window.open();
win.opener.focus();
}
}
</script>
</head>
<body >
<input type='button' onclick='openNew()' value='弹出窗体'>
</body>
</html>
window.opener.focus();
}else{
wy_openWindow();
} 现在我的网页出错。
出错信息:被呼叫方(服务器〔不是服务器应用程序〕)不可用并已消失。所有连续均无效,没有执行呼叫。
而且,每次重新打开,都需要访问后台,
原因就不说了,但问题还是可以解决,以下是我的解决方法从代码上分析,原因可能是 引用的变量或者对象已无效,所以在使用的时候加以判断了。 希望能帮到你。
// 全局变量 保存子窗口的对象
var scOpenWindow = null;function openNewWindow(url) {
// 是否需要重新打开子窗口
// 默认设置为 重新打开
var isOut = true;
if(scOpenWindow != null && scOpenWindow != "undefined" ) {
try {
// 判断当前子窗口对象是否可用
// 获取焦点!
scOpenWindow.focus();
// 如果OK,设置不需要重新打开子窗口
isOut = false;
} catch(e) {
// 异常来了
// 被呼叫方(服务器〔不是服务器应用程序〕)不可用并已 消失
// 释放对象资源
scOpenWindow.close();
scOpenWindow = null;
}
}
if(isOut) {
// 打开 子窗口,并将对象赋予给 变量 scOpenWindow
scOpenWindow = window.open(url,"xxx","xxx"); //
}
}