Solved

OnBeforeUnload / window.open

Posted on 2006-10-25
1
1,546 Views
Last Modified: 2008-01-25
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
0
Comment
Question by:HydeNSeeka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 6

Accepted Solution

by:
davbouchard earned 500 total points
ID: 17805214
It works for me. Could it be a popup blocker?
I also noticed you have a } in your second script before the </script> that doesn't seem to belong there.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question