Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onbeforeprint and popups 1

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
I have an ASP page which contains a chart and a table of data. I use CSS to have a "Screen" view and a different "Print" view so that I can eliminate all the navigation when the user attempts to print out the page. That all works fine.

However, when the user clicks on the print button, I want to ask them whether they want to print the table, the chart or both. To do this, I use the onbeforeprint function to open a popup which gives the user the various print options in a dropdown list. Once the user selects the option they want the popup sets the contents of the "Print" view in the parent window and closes.

My problem is this. How do I get the parent window to wait for the user to make the selection in the child window. I tried using a while loop in the parent window like:

window1 = window.open(......
while (!window1.closed) {}

However, this just hung up the browser. If I don't put in anything, then it just prints a blank page as the print fires before the user makes the selection in the popup.

Anyone tell me how this can be done??

Mighty
 
Do window.open() as usual. The rest of code place in separated function. When/if user makes selection in popup, call opener.function() before window.close().

For IE-only you can use window.showModalDialog(). It is somewhat tricky to use (no submit, no view source etc.), otherwise it does exactly what you need.
 
I don't understand how placing the rest of the code in a separate function is going to help me. Once the onbeforeprint function finished (window.open) it will print what is on the page - I don't want this to happen.

Mighty
 
Exactly - place code for printing there. When user selects table/chart/both, call this function from popup window. :)
 
Ack... i forgot about onbeforeprint event. In that case, use showModalDialog(). It stops execution of parent window while opened.
 
I wasn't aware of the showModalDialog - works a treat. It will only be on an Intranet page and all users in here use IE so it's perfect.

Thanks for the help.

Mighty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top