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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Opening a customized window with same url and closing the parent windo

    hello,

    here is a requirement.

    Opening a link in the browser has to open a new window with same url content (url cannot be hardcoded)

    and the opened window must close the parent window and should not have any of the status bar,url bar or menu bar.

    I have written this code in a html page in the body onload event

    var WIN_WIDTH = 700;
    var WIN_HEIGHT = 500;
    var MENUBAR_HEIGHT = 10;
    var TOOLBAR_HEIGHT = 50;
    var STARTUPBAR_HEIGHT = 10;
    var heightOfBars = MENUBAR_HEIGHT + TOOLBAR_HEIGHT + STARTUPBAR_HEIGHT;
    var xPos = (screen.width/2) - (WIN_WIDTH/2);
    var yPos = (screen.height/2) - (WIN_HEIGHT/2) - heightOfBars;

    var prop='menubar=no,scrollbars=no,status=no,locationbar=no,'+'toolbar=no,resizable=yes,width='+WIN_WIDT H+',height='+WIN_HEIGHT + ',left='+xPos+',top='+ yPos;

    window.open (location.href,'EKMIS',prop);

    //closes parent window without any confirmation
    window.opener.opener=''
    opener.window.close();


    But the problem is opened window goes into unending loop..

  • #2
    New Coder
    Join Date
    Jun 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You just need to test if the window was opened by another window. If it was, then don't run rest of the onload code.

    So, inside your onload function:

    Code:
    if (window.opened) {
    return true;
    } else
    {
    //your code here
    }

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    ALL BROWSERS that are patched will not allow you to close the parent window if you did not create it with JavaScript. SO you are out of luck here. Leave our windows alone. If I come to a site and it tries to change my window, I normally leave.

    If you are doing this presentation for more room. Try to redesign. If you are doing it for security reasons. It is a waste of time since the people you are hiding it from know how to get around it. If you are hiding it because it is effecting code on the server, you better learn how to fix it in the back end.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #4
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation

    The code
    if (window.closed){return true;}else{//code} is not working

    And

    Requirement i mentioned is not meant for a website but for a java web application.so trying to get around to view the content is handled by blocking the viewers and redirecting them to login screens.not concerned abt the security reasons,nor presentation.

    So if the parent window is closed crucial session information is lost once i open a new window, which is my requirement,
    New window has nothing but 2 input fields,which submit the data to server and ends the application.

    Cannot customize window from the forwarded page (coz i cant send any information to the forwarded page as it is handled by Application server-basic authentication procedure)

    Since my window is created from javascript, i am able to close parent window but not able to stop the un-ending loop of creating new window.

    Got any suggestions for that..

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,461
    Thanks
    0
    Thanked 632 Times in 622 Posts
    Maybe a cookie to track if the window replace has already been done.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well, it IS possible to close the current window... try

    window.opener=null;window.name="XYZ";window.open("","XYZ").close()

    this works for me in both IE and Gecko (Firefox,...)

    A1ien51 is still right to point out that only windows created by a script can be closed by the same script. The code above does just that. It reopens the current window thereby obtaining a new window handle which it can call close() upon.

    To fix the endless loop I would suggest you give the new window a certain name which you can query to see if you're already in the new window.


  •  

    Posting Permissions

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