近来网上经常流传一些关于如何在父窗口控制只弹出一个子窗口 问题,我查看了一些,大部分都是只能解决部分或者很麻烦,还不算完美。比如有人是实现的这样,使用的是Cookie,以下是例子。
主页上做了一个弹出窗口,如何使其只弹出一次,返回主页时不再弹出了。
---------------------------------------------------------------
<script>
window.open("http://www.yeboss.com.cn","yeboss","width=300,height=400")
</script>
---------------------------------------------------------------
cookie
---------------------------------------------------------------
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var expDays = 1; // number of days the cookie should last
var page = "only-popup-once.html";
var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie(count)
if(count == null) {
SetCookie(count,1)
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie(count)
SetCookie(count,newcount,exp)
return count
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function checkCount() {
var count = GetCookie(count);
if (count == null) {
count=1;
SetCookie(count, count, exp);
window.open(page, "", windowprops);
}
else {
count++;
SetCookie(count, count, exp);
}
}
// End -->
</script>
<BODY OnLoad="checkCount()">
这个是网上随便摘的一个例子,是不是感觉很多也很难看懂呢,下面我给大家说一种新方法,保证好看好使。
<script language="JavaScript" type="text/JavaScript">
<!-- Copyright fenggang at 2007/3/23
var w=null;
function MM_openBrWindow(theURL,winName,features) { //v2.0
if(w!=undefined&&isOpen()){
w.close();
}
w=window.open("",winName,features);
w.location.replace(theURL);
}
function isOpen()
{
try
{
w.document;
return true;
}
catch(ex)
{}
return false;
}
//-->
</script>
这个MM_openBrWindow()函数名是在Dreamweaver中常用的弹出窗口函数名,将这段代码放进页面里
然后再做弹出窗口就只能探出一个窗口了,以上是精髓部分,下面是完整的一个测试页的代码,试试看吧。
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="JavaScript" type="text/JavaScript">
<!-- Copyright fenggang at 2007/3/23
var w=null;
function MM_openBrWindow(theURL,winName,features) { //v2.0
if(w!=undefined&&isOpen()){
w.close();
}
w=window.open("",winName,features);
w.location.replace(theURL);
}
function isOpen()
{
try
{
w.document;
return true;
}
catch(ex)
{}
return false;
}
//-->
</script>
</head>
<body>
<a href="javascript:;" onClick="MM_openBrWindow(show.asp,,scrollbars=yes,resizable=yes,width=570,height=500)">title</a>
</body>
</html>
主页上做了一个弹出窗口,如何使其只弹出一次,返回主页时不再弹出了。
---------------------------------------------------------------
<script>
window.open("http://www.yeboss.com.cn","yeboss","width=300,height=400")
</script>
---------------------------------------------------------------
cookie
---------------------------------------------------------------
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var expDays = 1; // number of days the cookie should last
var page = "only-popup-once.html";
var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie(count)
if(count == null) {
SetCookie(count,1)
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie(count)
SetCookie(count,newcount,exp)
return count
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function checkCount() {
var count = GetCookie(count);
if (count == null) {
count=1;
SetCookie(count, count, exp);
window.open(page, "", windowprops);
}
else {
count++;
SetCookie(count, count, exp);
}
}
// End -->
</script>
<BODY OnLoad="checkCount()">
这个是网上随便摘的一个例子,是不是感觉很多也很难看懂呢,下面我给大家说一种新方法,保证好看好使。
<script language="JavaScript" type="text/JavaScript">
<!-- Copyright fenggang at 2007/3/23
var w=null;
function MM_openBrWindow(theURL,winName,features) { //v2.0
if(w!=undefined&&isOpen()){
w.close();
}
w=window.open("",winName,features);
w.location.replace(theURL);
}
function isOpen()
{
try
{
w.document;
return true;
}
catch(ex)
{}
return false;
}
//-->
</script>
这个MM_openBrWindow()函数名是在Dreamweaver中常用的弹出窗口函数名,将这段代码放进页面里
然后再做弹出窗口就只能探出一个窗口了,以上是精髓部分,下面是完整的一个测试页的代码,试试看吧。
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="JavaScript" type="text/JavaScript">
<!-- Copyright fenggang at 2007/3/23
var w=null;
function MM_openBrWindow(theURL,winName,features) { //v2.0
if(w!=undefined&&isOpen()){
w.close();
}
w=window.open("",winName,features);
w.location.replace(theURL);
}
function isOpen()
{
try
{
w.document;
return true;
}
catch(ex)
{}
return false;
}
//-->
</script>
</head>
<body>
<a href="javascript:;" onClick="MM_openBrWindow(show.asp,,scrollbars=yes,resizable=yes,width=570,height=500)">title</a>
</body>
</html>
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“用javascript父窗口控制只弹出一个子窗口”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。