views:

771

answers:

2

Hi EveryBody, I have a problem with browsers window managament with javascript. I have two page in my proof of concept application. First page contains login information (username, password, login button etc.) and second page is a managament screen. I need that when the user pressed to the login button on the login screen it open to main screen and main screen must be open new window without full screen. I mean close, minimize, maximize buttons and bottom bar of the windows os must be stayed on the screen.

During opening the new window on the login screen, it must be close itself automatically. I have found many example script but every script giving same results to me.

For example; following script solving my problem but same problems continue for me,

firefox does't close opener window it self, ie 6.0 closing opener window - it's working ie 7.0 - 8.0 before the close it self it asking "The webpage you are viewing is trying to close the window".

          window.open("Content/StartPage.aspx", windowName, "menubar=0, location=0, resizable=1, status=1, width=" + screen.width + ",height=" + screen.height);
        if (window.name != windowName) {
            var me = window.self;
            me.opener = window.self;
            me.close();
        }

How can i open new window and close the opener with above requirements without ask browsers question ?

Thank you.

+2  A: 

You cannot do it according the security assurance of browser, there are some action which doesn't allow to be managed directly via javascript without user interference.

Artem Barger
A: 

Try something like this in your new window, on the body onload:

function closeParent()
{ 
    try
    { 
     var op = window.opener; 
     op.opener = self; 
     op.close();        
    } 
    catch(er) {} 
}

Still, this solution isn't perfect, I only got it to work in Internet Explorer, and even then, I got a warning popup for closing the parent window. This might be something that can't feasibly be solved.

theJerm
It didn't work, i guess browsers main window doesn't close with script, but it should be achieve via some way. Thans for your suggestion.
fyasar
Yeah, it's definitely an imperfect solution... Hopefully something is found that can solve this.
theJerm