如何用javascript关闭和载入窗口
展开全部
关闭2个方案
1:将window.open();方法返回的对象放在一个变量里,如:
var winObject = window.open("xxx.htm","_blank");
这样就可以用winObject对象来操作已经弹出的窗口,比如:
if (!winObject.closed) //判定是否已经关闭,已经关闭时值为true
{
winObject.close();
}
这样就可以关闭
2:可以在已经弹出的子窗口中调用父窗口的函数来使子窗口关闭,如父窗口中有一个函数为:
var winObject = window.open("xxx.htm","_blank");
function closeTest()
{
if (!winObject.closed)
{
winObject.close();
}
}
子窗口可以通过一个对象来调用
window.opener.closeTest();
OK了
-----------------------
//本窗口(弹出窗口)关闭,刷新父窗口
<script>window.opener.parent.location.reload();window.close()</script>
//后退一页
<a href="javascript:history.go(-1);">返回前页</a>
//新弹出窗口
<script language=JavaScript>
function newin(url,name,size)
{
var windowname=window.open(url,name,"left=0,top=0,status=no,scrollbars=no,resizable=no,"+size);
}
</script>
<a href=Javascript:newin('x.htm','Review','width=500,height=400')>查看简介</a>
//页面自动返回
<meta http-equiv="refresh" content="1;url=bigclass.asp">
<p align=center><font color=red>恭喜您!您选择的大类已经被删除!<br>1秒钟后返回上页!</font>
//关闭窗口
<a href="javascript:window.close();">点击这里关闭本窗口</a>
//载入时弹出窗口
<script language="JavaScript">
window.open('http://www.leshanju.6to23.com/','','toolbar,menubar,scrollbars,resizable,status,location,directories,copyhistory
,height=400,width=750');
</script>
//弹出窗口自动关闭
<script language="JavaScript">
function close() {
setTimeout("self.close()",10000) //毫秒
}
</script>
<body onload="close()">
//只弹出一次的窗口
<script>
function openwin(){
window.open("page.html","","width=200,height=200")
}
function get_cookie(Name) {
var search = Name + "=" var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function loadpopup(){
if (get_cookie("popped")=="){
openwin()
document.cookie="popped=yes"
}
}
</script>
<body onload="loadpopup()">
//控制新开窗口属性
<input type="button" Value="打开新窗口"
ONCLICK="window.open('test.htm', 'Sample',
'toolbar=yes,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=300,height=20
0,left=100,top=100')">
//web窗体对话框
<script language=javascript>
function logonApprove()
{
var
result=window.showModalDialog("ubbfaces.asp",window,"scroll:no;resizable:no;help:no;status:no;dialogWidth:400px;dialogHeight:
250px");
}
</script>
1:将window.open();方法返回的对象放在一个变量里,如:
var winObject = window.open("xxx.htm","_blank");
这样就可以用winObject对象来操作已经弹出的窗口,比如:
if (!winObject.closed) //判定是否已经关闭,已经关闭时值为true
{
winObject.close();
}
这样就可以关闭
2:可以在已经弹出的子窗口中调用父窗口的函数来使子窗口关闭,如父窗口中有一个函数为:
var winObject = window.open("xxx.htm","_blank");
function closeTest()
{
if (!winObject.closed)
{
winObject.close();
}
}
子窗口可以通过一个对象来调用
window.opener.closeTest();
OK了
-----------------------
//本窗口(弹出窗口)关闭,刷新父窗口
<script>window.opener.parent.location.reload();window.close()</script>
//后退一页
<a href="javascript:history.go(-1);">返回前页</a>
//新弹出窗口
<script language=JavaScript>
function newin(url,name,size)
{
var windowname=window.open(url,name,"left=0,top=0,status=no,scrollbars=no,resizable=no,"+size);
}
</script>
<a href=Javascript:newin('x.htm','Review','width=500,height=400')>查看简介</a>
//页面自动返回
<meta http-equiv="refresh" content="1;url=bigclass.asp">
<p align=center><font color=red>恭喜您!您选择的大类已经被删除!<br>1秒钟后返回上页!</font>
//关闭窗口
<a href="javascript:window.close();">点击这里关闭本窗口</a>
//载入时弹出窗口
<script language="JavaScript">
window.open('http://www.leshanju.6to23.com/','','toolbar,menubar,scrollbars,resizable,status,location,directories,copyhistory
,height=400,width=750');
</script>
//弹出窗口自动关闭
<script language="JavaScript">
function close() {
setTimeout("self.close()",10000) //毫秒
}
</script>
<body onload="close()">
//只弹出一次的窗口
<script>
function openwin(){
window.open("page.html","","width=200,height=200")
}
function get_cookie(Name) {
var search = Name + "=" var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function loadpopup(){
if (get_cookie("popped")=="){
openwin()
document.cookie="popped=yes"
}
}
</script>
<body onload="loadpopup()">
//控制新开窗口属性
<input type="button" Value="打开新窗口"
ONCLICK="window.open('test.htm', 'Sample',
'toolbar=yes,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=300,height=20
0,left=100,top=100')">
//web窗体对话框
<script language=javascript>
function logonApprove()
{
var
result=window.showModalDialog("ubbfaces.asp",window,"scroll:no;resizable:no;help:no;status:no;dialogWidth:400px;dialogHeight:
250px");
}
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询