SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hyperlink Changing Parent Window and Closing Popup

    Hi,

    How can I do this so that both happen at the same time?

    Any help is greatly appreciated,
    -Corbb

    P.S. I'm rather new to JavaScript, so please provide as much code and documentation as possible. Thanks!
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  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)
    Quite simple; just call the closePopup() function on unload.
    If you want the popup closed when clicking on a specific link, call closePopup() on the onClick event for the link instead.
    (The call to closePopup() in openPopup() is just an extra thing, to avoid more than 1 popup window opened by this page)
    Code:
    <html>
      <head>
        <script language="JavaScript">
          var w = null;
          function openPopup()
          {
            closePopup();
            w = window.open('', '', 'width=200,height=200');
            w.document.write('Hello, I just popped up');
          }
          function closePopup()
          {
            if(w != null)
            {
              w.close();
            }
          }
        </script>
      </head>
      <body onUnload="closePopup();">
        <a href="javascript:void(0);" onclick="openPopup();">Open popup</a>
        <br>
        <a href="anotherpage.htm">A link to another page</a>
      </body>
    </html>

  3. #3
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, read your question one more time and realized that you wanted to change the parent window's location and then close the popup - from the popup window.
    Here's an updated openPopup() function and a new change() function (same html and closePopup() code as in the previous post)
    Code:
          function openPopup()
          {
            closePopup();
            w = window.open('', '', 'width=200,height=200');
            var s = 'Hello, I just popped up<br>';
            s += '<a href="javascript:void(0);" onClick="window.opener.change();">';
            s += 'Change parent and close me</a>'
            w.document.write(s);
          }
          
          function change()
          {
            window.location.href = 'anotherpage.htm';
          }
    Last edited by jofa; Jul 7, 2002 at 14:38.

  4. #4
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Huh?

    Hi,

    Thanks for your help. However, I'm very confused.

    I have a popup window that opens when somebody visits my website. There is a form in this winodw where somebody enters their email address. Then a "thank you" page comes up. In the "thank you" page, it says "If you have any questions, please don't hesitate to contact us." The contact us is linked to /contactus.htm. When somebody clicks on "contact us," I want the popup to close and then the parent window to change to contactus.html. How can I do this?

    You may have already answered this, but I'm confused.

    Thanks,
    Corbb
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  5. #5
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want the popup to close and then the parent window to change to contactus.html. How can I do this?
    In the popup, add this link:
    <a href="javascript:void(0);" onClick="window.opener.location.href='contactus.html';">Contact us</a>

  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)
    And, of course, if you don't have the
    <body onUnload="closePopup();">
    in the main page, you must add
    window.close; to the link in the popup:
    <a href="java script:void(0);" onClick="window.opener.location.href='contactus.html';window.close();">Contact us</a>

  7. #7
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    jofa,

    Thank you very much!

    -Corbb
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

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

    a twist

    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


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
  •