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
Solved

OnBeforeUnload / window.open

Posted on 2006-10-25
1
1,543 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

839 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