Use JavaScript parent window to control only one child window _javascript tips

Source: Internet
Author: User
Tags setcookie
Recently on the Internet a lot about how to control in the parent window only a child window problem, I looked at some, most of them can only be solved part or very troublesome, not perfect. For example, someone is implementing this, using a cookie, and here's an example.
The home page has a pop-up window, how to make it pop only once, return to the home page no longer pop-up.
---------------------------------------------------------------

<script>
window.open ("http://www.yeboss.com.cn", "Yeboss", "width=300,height=400")
</script>
---------------------------------------------------------------

Cookies
---------------------------------------------------------------


<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 ()" >
This is the Internet casually picked an example, is not a lot of it is difficult to understand, I would like to say a new method, to ensure good looks.

<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>
This Mm_openbrwindow () function name is the pop-up function name that is commonly used in Dreamweaver, and this code is put into the page
Then do pop-up windows can only explore a window, the above is the essence of the section, the following is a complete test page code, try it.
<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </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>
<body>
<a href= "javascript:;" onclick= "Mm_openbrwindow" (show.asp,,scrollbars=yes,resizable=yes,width=570,height= ) ">title</a>
</body>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.