SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast Fifal's Avatar
    Join Date
    Oct 2005
    Location
    Windhoek Namibia
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Self close a Pop-Up -> then opening link in a new browser window??

    Hi folks,

    I have a couple of Pop-Ups which contain links. These links should self close the Pop-Up, and then open up a new browser window to follow the link. I'm using the following function - but where do I specify that a new browser window should be used when someone clicks on the link (basically like a target: blank)?

    PHP Code:
    function goAndClose(url) {
      
    opener.location.href url
      this
    .close;

    and the link in the Pop-Up is marked like this:

    PHP Code:
    <a href="javascript:self.close();" onclick="goAndClose('http://www.google.com/')">Google</a
    Can someone help me out?

    And by the way: does someone know if its actually possible to force up opening a new browser tab (in IE7/Firefox) instead of a new browser window??

  2. #2
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Devon, UK
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code will open the URL in the window that opened the popup.

    You open a new window with window.open(). You can then close the current window with window.self.close();

    But, in general, I'd recommend you avoid popups where possible.

  3. #3
    SitePoint Enthusiast Fifal's Avatar
    Join Date
    Oct 2005
    Location
    Windhoek Namibia
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your input! Yeah, I'm also not a fan of pop ups, but in this case it's how the client wants it: its actually an image gallery. Each image opens up in a pop up and has a link underneath - to an external website.
    Clicking this link should close the pop up and open up the website in a new browser window...

    Sorry, but do you mind giving me a code example? I'm not really good in JS and cant get it right :-(

    PHP Code:
    function goAndClose(page) {
      
    //opener.location.href = page
       
    window.open(page"mywindow");
      
    //this.close;
      
    window.self.close();

    doesnt really work... can u help me out?

    Big Thx!

  4. #4
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Devon, UK
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK - this is completely untested, but it's got a little progressive enhancement...

    Code:
    function goAndClose() {
    window.opener.location.href=this.href;
    window.self.close();
    }
    The HTML would then be:
    Code:
    <a href="http://www.google.com/" onclick="goAndClose();">Google</a>
    Hope that helps.

  5. #5
    SitePoint Enthusiast Fifal's Avatar
    Join Date
    Oct 2005
    Location
    Windhoek Namibia
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ceeb,

    thanks for your reply... I tried the code snippet (and a couple of modifications), but unfortunately it didn't work :-(

    Can someone else maybe help out? :-(

    Again, here's what I'm looking for:

    function which first closes the pop-up by clicking on a link, then opening up a new browser window which opens up the link.

    any input is highly appreciated!

  6. #6
    SitePoint Enthusiast csjc2662's Avatar
    Join Date
    Feb 2007
    Location
    Texas, USA
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Try This

    This worked in IE6. and opened the new page in FF. I didn't open a popup to use it but it will work better with one.
    Code:
    <script language="javascript" type="text/javascript">
    <!--
    function goAndClose(page) { 
      
       window.open(page); 
        window.close(name_of_Popup);//insert the name of the popup 
    //window here.  will only work properly if popup was created with window.open. 
    //havent gotten it to work in ff but I started with the window to be closed 
    //didnt open a popup to start... 
    } 
    </script>
    <a href="javascript:void();" onclick="goAndClose('http://www.google.com/');">Google</a>
    here is a refrence of windows metodshttp://www.devguru.com/...QuickRef/window.html
    hope this helps
    James
    New links coming soon....


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
  •