Link to home
Start Free TrialLog in
Avatar of HydeNSeeka
HydeNSeeka

asked on

OnBeforeUnload / window.open

I am trying to open a popup in the onbeforeunload event of an aspx page. It works fine the first time but will not do it after that. I put an alert in so I know the onbeforeunload event is firing so I think my issue is with the window.open.

Here is the code I am using

StringBuilder sbConfirmExit = new StringBuilder();

sbConfirmExit.Append("<script>");
sbConfirmExit.Append("window.onbeforeunload = confirmExit;");
sbConfirmExit.Append("var postback = false; function confirmExit() { ");
sbConfirmExit.Append("if(postback == true) ");
sbConfirmExit.Append("event.cancelBubble = true; ");
sbConfirmExit.Append("else ");
sbConfirmExit.Append("OpenExitWindow();");
sbConfirmExit.Append(" }</script>");
                  
                        
this.Page.RegisterStartupScript("ConfirmClose",sbConfirmExit.ToString());
                        
StringBuilder sbOpenWindow = new StringBuilder();
sbOpenWindow.Append("<script language=\"javascript\">");
sbOpenWindow.Append("var NewWindow;");
sbOpenWindow.Append("function OpenExitWindow(){alert('innewwindow');");
sbOpenWindow.Append("NewWindow = window.open(\"Exit.aspx\",\"win\",\"target=_blank,location=yes,status=yes,toolbar=yes,menubar=yes,scrollbars=yes,titlebar=yes,resizeable=yes\");");
sbOpenWindow.Append("} </script>");
                              
this.Page.RegisterStartupScript("OpenWindow", sbOpenWindow.ToString());

Thank you
ASKER CERTIFIED SOLUTION
Avatar of davbouchard
davbouchard

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