SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member pessentials's Avatar
    Join Date
    Oct 2003
    Location
    reno, nv
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question stopping a popup from loading again on refresh or page change

    can anyone tell me how I can stop a pop up window i have on my web site to not come up when a customer refreshes or changes pages?

    this is the script im using

    <SCRIPT LANGUAGE="javascript">
    window.open('http://www.printeressentials.com/ink/index.php', 'logo', config='height=700,width=300')
    </SCRIPT>

    what can i do?

    Brian

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The standard way is by setting a cookie to record the initial pop-up, and prevent repeats:

    http://simplythebest.net/info/javascript45.html

    I prefer this approach:
    Code:
    <script type="text/javascript" language="javascript">
    
    if (!/_popdone_/.test(self.name))
    {
    	window.open('http://www.google.com', 'logo', 'height=700,width=300');
    	self.name += '_popdone_';
    }
    
    </script>
    Names the window, won't re-open the pop-up again. Works even if cookies are disabled. If you're using a frameset, be sure and embed this in the frameset document, since the frames (which are windows, basically) will be named.
    ::: certified wild guess :::

  3. #3
    SitePoint Member pessentials's Avatar
    Join Date
    Oct 2003
    Location
    reno, nv
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried your script you had but it still loads the popup again...does it matter where I put the code? in the head? or the body?

    also on that link for the cookie, the page already has a
    onLoad="self.name = 'main'" for something else in the body, how can I add what that link says to do onLoad="checkCount()" ????

    any ideas?

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See this?

    onLoad="self.name = 'main'"

    You already have code naming the window (self is a synonym for window). Oops.

    Change the script; this goes in the <head>:
    Code:
    <script type="text/javascript" language="javascript">
    
    if (!/main/.test(self.name))
    	window.open('http://www.google.com', 'logo', 'height=700,width=300');
    
    </script>
    If that doesn't work - it should - for that cookie:
    Code:
    <body onload="self.name='main';checkCount()">
    ::: certified wild guess :::


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •