Solved

OnBeforeUnload / window.open

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This video teaches users how to migrate an existing Wordpress website to a new domain.
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now