主頁上做了一個彈出窗口,如何使其只彈 " /> 欧美日韩综合视频网址,综合久久综合,国产欧美日韩电影

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

用javascript父窗口控制只彈出一個子窗口

近來網(wǎng)上經(jīng)常流傳一些關于如何在父窗口控制只彈出一個子窗口 問題,我查看了一些,大部分都是只能解決部分或者很麻煩,還不算完美。比如有人是實現(xiàn)的這樣,使用的是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()"> 
這個是網(wǎng)上隨便摘的一個例子,是不是感覺很多也很難看懂呢,下面我給大家說一種新方法,保證好看好使。

<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()函數(shù)名是在Dreamweaver中常用的彈出窗口函數(shù)名,將這段代碼放進頁面里
然后再做彈出窗口就只能探出一個窗口了,以上是精髓部分,下面是完整的一個測試頁的代碼,試試看吧。
<%@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>

JavaScript技術(shù)用javascript父窗口控制只彈出一個子窗口,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 富平县| 泾川县| 舟曲县| 潞西市| 边坝县| 福鼎市| 绥江县| 兴仁县| 宁南县| 阜新市| 潜江市| 怀远县| 普定县| 万安县| 九龙县| 南丰县| 锦屏县| 盐津县| 霸州市| 正定县| 东乡族自治县| 禹州市| 孙吴县| 玉环县| 萝北县| 溧水县| 天长市| 香河县| 宁明县| 赫章县| 和林格尔县| 车险| 扶风县| 威远县| 苗栗县| 邢台市| 景德镇市| 寿阳县| 焦作市| 张家界市| 江都市|