Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Link in Javascript window: close window + open new doc in reg. window

    Hi!
    I need help with this little problem:
    A presentation opens in a Javascript window. In that window, I want a link that does two things:
    1. closes the Javascript window
    2. opens a new document in the parent window (=the regular browser window which had the link that opened the js. window.)

    To get either one of these things done is easy; the hard part for me is getting both things done with one mouse click.
    And, of course, the whole thing should be cross-browser compatible...
    I really don't know much about javascript, so I use scripts from places like Dynamic Drive.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This should give an idea
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    <!--
    function openWin(){
    newwin=window.open('','','width=400,height=400');
    newwin.document.open();
    newwin.document.write('<a href="#" onclick="opener.window.location=\'http://www.codingforums.com\';window.close();return false">close me</a>');
    newwin.document.close();
    }
    //-->
    </script>
    </head>
    
    <body>
    <a href="#" onclick="openWin();return false">link</a>
    </body>
    </html>
    if you are going to have this popup page already made, then just put this link in it
    Code:
    <a href="#" onclick="opener.window.location=\'http://www.codingforums.com\';window.close();return false">close me</a>

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    main page:
    Code:
    function doOpen(url, target){
      var w = window.open(url, target, 'width=800, height=600, resizable=1');
      w.focus();
      return false;
    }
    ...
    <a href="popup.htm" target="mypopup" onclick="return doOpen(this.href, this.target)">popup</a>
    popup page:
    Code:
    function closeMe(){
      if (opener && !opener.closed){ //ensures that opener is still open
        opener.location.href = "newpage.htm";
        opener.focus();
      }
      window.close();
      return false;
    }
    ...
    <input type="button" value="Close" onclick="closeMe()" />
    or:
    <a href="#" onclick="return closeMe()">Close</a>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Many thanx to both of you guys!
    Really fantastic to get such good help for free!

    Yes, I already have a very good popup-script which centers the popup.
    So all I needed was the closing-code.

    The one supplied by glenngv proved easiest to handle in my hands.


    Again, many thanx!


  •  

    Posting Permissions

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