I am facing an interesting issue:
Currently I have a button that says “Print”, which is located at the end of a series of pages where users can enter information, make selections and obtain a unique result.
When they press this button, data representing the state of the application will be sent via JQuery’s .post(). Once the target script processes that data and stores it in the database against a unique ID, that ID is sent back to the success handler. The ID is then used in the success handler to open a new window that will pull down the data they sent off and display it in a printable manner.
$.post("api/PrintJob.php", applicationStateJSON, function(response)
{
window.open("print/?job=" + response.token);
}, "json");
Because the window.open() call is not directly within a click handler, the popup is understandably blocked.
I can’t simply use window.location.href = ?; because the state of the application needs to be maintained in case the user wants to go back a step and make some changes, etc.
Currently my only solution is to have a secondary button appear within the success handler, and have that launch the print window. I would however prefer to retain the current feel and have the window open in a new tab / window / popup / whatever if possible, without being blocked.
Maybe there is a way that I can launch the popup empty when I initially click print, and then reload it when the data has hit the database?
Any ideas are welcome.
My suggestion will be to open a window on first click and then do a post from the newly opened window. The response of the post is received in the newly opened window. This response can be used to paint the new window using JS/JQuery.