Link to home
Start Free TrialLog in
Avatar of dumbASP
dumbASP

asked on

Open New Window and close Previous window


I'm looking for a script that will automatically open a new window when the page is loaded and will close the initial window. The new window will need to have a height of 450 and width of 95%. I will also need the option to choose whether or not to show browser elements.

Any suggestions?
Avatar of apollois
apollois

Hi dumbASP,

Use the BODY onLoad event to call a custom Javascript function.  Let me know if you have any questions.

================================================
<HTML>
<HEAD>

<script LANGUAGE="javascript">
<!--

//---------------------------------------------------------------------
function DisplayWindow(pcURL) {
//---------------------------------------------------------------------
         
     var popup;
     var intWidth      = 518;
     var intHeight      = 700;
     var intTop           = 0;    
     var intLeft      = 400;
     var strFeatures = 'toolbar=0,scrollbars=1,location=0, '
                    + 'statusbar=0,menubar=0,resizable=1,'
                    + 'width='+intWidth+',height='+intHeight+',left ='+intLeft+',top ='+intTop+'';
                   
     popup = window.open(pcURL, "HealthPlan", strFeatures);
     
     //Close Original Window -- this will cause a confirmation dialog box
     //to be displayed to the user.  You cannot avoid this.

     window.close
}
//-->
</script>

</HEAD>
<BODY onLoad="DisplayWindow('NewWindowURL.asp');">
</BODY>
</HTML>

================================================

Best Regards,
>apollois<
Avatar of dumbASP

ASKER



The open in new window portion works great .. thanks...

However... the close window portion is not working. It is simply leaving a blank window open on the screen.
window.close();
ASKER CERTIFIED SOLUTION
Avatar of apollois
apollois

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Don't know your exact situation, why don't you just resize the current window instead of launching a new one and then closing the old one????


window.resizeTo(400,300)
window.location.href='blahblahblah.htm'


Brett
i would also go with resizing... because the user gets asked, if he really allows you to close the parent window...
to avoid this, just resize the win...

ASPGuru
ASPGuru,

>>> i would also go with resizing. <<<

Resizing avoids the close window dialog, but does not allow you to remove the browser menus/bars.  Sometimes you want to present a clean window without all the browser menus/bars/etc.  I often do this in apps where I have a main page that spawns "sub-windows".  It looks more professional -- almost like a windows app. <bg>

Best Regards,
>apollois<
yea sure... everything has benefits and drawbacks...

dumbASP needs to decide...

ASPGuru
i'm not getting any warnings on window.close();..
is it because windows.close() executed from within a child pop-up window?
DRY_GIN,

>>> i'm not getting any warnings on window.close();.. <<<

If you create the window, you can close it without warning.

Best Regards,
>apollois<
Avatar of Gary
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by apollois

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer