SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    London
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Closing pop-up window

    Does anyone know how to have a pop-up window close once someone's clicked on a link? And can cookies be incorporated into this so that the window only pops up once a day?

    At the minute, when someone clicks on a link, it opens up the page behind the window so you have to then also close the window. This is the script now:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0030)http://www.nof.org.uk/news.cfm -->
    <html><head><title>Quick Links to....</title>

    <body bgcolor="#003399" vlink="#ccff66" alink="#33cc00" link="#ccff66" leftmargin="0"
    topmargin="0">
    <div align="center">
    <table cellspacing="0" cellpadding="15" width="350" border="0">
    <tr>
    <td><font face="arial" color="#ffffff" size="2">
    <div align="center">
    <p><img height="26" alt="Additions to this website" src="gif/newspop_hd.gif" width="283" border="0"><br>
    <br>
    <!--- <p>Latest general information, including contact details can be found <A onclick="window.opener.location='generalleaflet/ngl.htm';" href="http://www.nof.org.uk/news.cfm#"><b>here</b></a>&gt;&gt;</p> --->
    <!--- <p>Our <A onclick="window.opener.location='news/mission/mission1.htm';" href="http://www.nof.org.uk/news.cfm#"><b>Mission and Values 2001/02</b></a> &gt;&gt;</p> --->
    <br>
    <FONT face="arial" size="2"><FONT face="arial" size="2"><A onclick="window.opener.location='index.cfm?loc=edu&inc=oosc_ni1'" href="news.cfm"><B>Childcare
    - Extra Funding in Northern Ireland</B></A><BR>
    <B>&pound;3 million extra</B> now available to assist with capital
    expenditure needed to obtain registration.</FONT></FONT>
    <p><font face="arial" color="#ffffff" size="2"><a onClick="window.opener.location='index.cfm?loc=env&inc=space';" href="news.cfm"><b>Transforming
    your space</b></a></font>: <font face="arial" color="#ffffff" size="2"><b>&pound;49.5
    million</b></font> <font face="arial" color="#ffffff" size="2">available</font>
    as part of the transforming communities initiative<b>.</b></p>
    <p><A onclick="window.opener.location='index.cfm?loc=hea&inc=boscot';" href="news.cfm"><b>Better Off</b></a>: <b>&pound;10 million</b>
    for rehabilitation of people in Scotland who misuse or have misused
    drugs.</p>
    <p><A onclick="window.opener.location='index.cfm?loc=fairshare&inc=main';" href="news.cfm"><b>Fairshare</b></a>b>
    &pound;169 million</b> for <b>62</b> disadvantaged communities across
    the UK. </p>
    <p>The latest Initiative newsletter is available online.
    <A onclick="window.opener.location='index.cfm?loc=news&inc=Initiative/initiative11/front';" href="news.cfm">
    Read the latest news and articles about our projects.</a></p>
    <p>Keep up to date with the news from the New Opportunities
    Fund through our <A onclick="window.opener.location='index.cfm?loc=news&inc=pressview';" href="news.cfm">press
    releases.</a><br>
    </p>
    <p> <A href="javascript: window.close()"><img height="18" alt="Close window" src="gif/newspop_close.gif" width="102" border="0"></a>
    </p>
    </div>
    </font></td>
    </tr>
    </table>
    </div>
    </body>
    </html>

    I'd appreciate any help

    Cheers
    Jo

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    onclick="window.opener.location='index.cfm?loc=fairshare&inc=main';window.close();"

  3. #3
    SitePoint Evangelist
    Join Date
    May 2002
    Location
    Barcelona, Spain
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    closing a window when a page loads

    How about a twist on this:

    I have a page with a link that loads another page. No problem, straight html. However the loaded page takes some time to load since it's parsing some PHP. So I created a little javascript that opens a new popup window that says "your page is being loade, chill out" or something. I called this popup window "popup" from the javascript that opens it:

    onClick="window.open('url', 'popup', width, height)

    Now what I want to do is close the popup window once the called page loads. So I thought that if I put into the called page:

    <body onLoad="window.close('popup')>

    it would do the trick, but all it does is close itself! How can I tell it to close the popup window?
    Used to prefer PHP.
    Now I prefer Maya but stuck with PHP
    bruji.com

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If window A opens the windows B and C, you can have a function in A that closes C, and call this function from B with window.opener.closeC()

    Example, in A:
    Code:
    var B = window.open(blahblah...);
    var C = window.open(blahblah...);
    function closeC()
    {
      if(C != null)
      {
        try    // maybe the user closed it?
        {
          C.close();
        }
        catch(e)
        {
          C = null;
        }
      }
    }
    And in B:
    Code:
    <body onload="window.opener.closeC();">

  5. #5
    SitePoint Evangelist
    Join Date
    May 2002
    Location
    Barcelona, Spain
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this is getting me closer. But the problem I'm having is that window A opens window B as the popup, yet it does it from a link so Window A is now taken to a different page. I want window A to close window B when it finishes loading the new page

    In your code, (I'm new to javascript) it seems that you're equating B with the actual opening of the popup window. I tried doing this from the link but it doesn't seem to work:
    PHP Code:
    <a href"print.php" onClickonClick=\" newWindow = window.open('printingpopup.html', 'popup', 'height=100, width=320, top=100')\" >Print</a> 
    then on the new window A (print.php):

    <body onLoad="close(newWindow)>
    I even tried, like in your example:

    <body onLoad="newWindow.close()">

    Nothing. The little bugger doesn't close. This is drivin gme nuts!
    Used to prefer PHP.
    Now I prefer Maya but stuck with PHP
    bruji.com

  6. #6
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you navigate to another url in window A, then the variable newWindow definitely will go out of scope

    Maybe you could try using a frameset with one "invisible" frame (height = 0) to store the reference to the popup in?

  7. #7
    SitePoint Evangelist
    Join Date
    May 2002
    Location
    Barcelona, Spain
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jofa, how would I do that (try using a frameset with one "invisible" frame (height = 0) to store the reference to the popup in? I mean storing the reference there, I know how to create frames.

    Another question, is there a way to send the scope from one page to the next in javascript?

    (I know it sounds stupid because the scope is the page itself as I understand it, but I'm just fishing for solutions here).

    You know what's weird though is that that idea I got it from Ebay, when you fill out their form and hit the button to submit an image a window pops up and then dissapears as soon as the file is uploaded. I guess they might be doing the frame trick or looking at the file not to increase any more???
    Last edited by pata; Nov 14, 2002 at 15:15.
    Used to prefer PHP.
    Now I prefer Maya but stuck with PHP
    bruji.com


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
  •