Basically, what it does is, close the popup, execute that window.location call which creates a PDF, then executes window.open() to open another popup to see if there are any more PDF's that can be created. This works fine in Firefox, but that window.open() never gets executed in IE 9.
Tried some google searches, but nothing came up.
I've rewritten this several times and can't get it to work in IE 9. Here's one of my rewrites:
window.close(); // the CURRENT WINDOW is now closed...NO OTHER CODE can use the current window
// so this next line is meaningless, since the current window no longer exists.
window.location='index.php?module=Patient_Procedure&action=genMFGPO'&pomode=create&kindofpo=Z';
// this next code might work, but it might not...
// ...because once the current window is closed where is the JS code supposed to be working?
window.open(\'index.php?module=Patient_Procedure&action=genMFGPO&pomode=preview','poverifywin','width=1250,height=1000,status=0,resizable=1,scrollbars=1,toolbar=0,menubar=0,location=0')
If you want to close the current popup, that must be the *LAST* thing you do.
But what I don't understand is where the PDF file you say the middle statement opens is supposed to go if you are (a) trying to put it into the current window [which is what window.location will do] and (b) trying to close the current window.
That just makes no sense, at all.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
window.close(); // the CURRENT WINDOW is now closed...NO OTHER CODE can use the current window
// so this next line is meaningless, since the current window no longer exists.
window.location='index.php?module=Patient_Procedure&action=genMFGPO'&pomode=create&kindofpo=Z';
// this next code might work, but it might not...
// ...because once the current window is closed where is the JS code supposed to be working?
window.open(\'index.php?module=Patient_Procedure&action=genMFGPO&pomode=preview','poverifywin','width=1250,height=1000,status=0,resizable=1,scrollbars=1,toolbar=0,menubar=0,location=0')
If you want to close the current popup, that must be the *LAST* thing you do.
But what I don't understand is where the PDF file you say the middle statement opens is supposed to go if you are (a) trying to put it into the current window [which is what window.location will do] and (b) trying to close the current window.
That just makes no sense, at all.
By meaningless, do you mean that it won't run, because it does. The window.location does execute, it's just the final window.open() that doesn't run. I didn't write this, just trying to fix it so that it runs in IE. This code runs fine in Firefox.
Also, I'm not displaying the PDF, just generating it and saving it locally.
Last edited by hadoob024; 09-24-2012 at 10:36 PM..
It's a question of timing: It is completely dependent on WHEN things happen. In Firefox, apparently both of the calls happen before the window.close() completes. In MSIE, clearly that doesn't happen.
Once you call window.close() on the current window, there's no guarantee what code, if any, will run from that window. For that matter, once you do window.location, there is no guarantee any code from the prior location will be able to run.
I would suggest that the way to do this would be to use AJAX, instead of window.location, to generate the PDF file (and you can just ignore the return from the AJAX call, then), then do the window.open() for the new popup, then do the window.close().
By calling AJAX, you aren't depending on any timing of events.
And not to ask a silly question, but...instead of doing the window.open to create a new popup and then closing the current one, why not just use window.location to replace the current popup with the new one?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
It's a question of timing: It is completely dependent on WHEN things happen. In Firefox, apparently both of the calls happen before the window.close() completes. In MSIE, clearly that doesn't happen.
Once you call window.close() on the current window, there's no guarantee what code, if any, will run from that window. For that matter, once you do window.location, there is no guarantee any code from the prior location will be able to run.
I would suggest that the way to do this would be to use AJAX, instead of window.location, to generate the PDF file (and you can just ignore the return from the AJAX call, then), then do the window.open() for the new popup, then do the window.close().
By calling AJAX, you aren't depending on any timing of events.
And not to ask a silly question, but...instead of doing the window.open to create a new popup and then closing the current one, why not just use window.location to replace the current popup with the new one?
Cool. Thanks for the tips!
Honestly, I didn't know about it
I'm more of a backend programmer than a front-end developer. Just found out about that window.location.replace yesterday.
If you are not using jQuery for other things on the page, it's not worth dragging in that whole library for something as simple as this.
Code:
// use AJAX to start creation of the new PDF
var http = window.XMLHttpRequest != null
? new XMLHttpRequest()
: new ActiveXObject("Microsoft.XMLHTTP");
http.open("GET","index.php?module=Patient_Procedure&action=genMFGPO'&pomode=create&kindofpo=Z",true);
http.send( );
// ignore the asynch response
// then just change the current popup to the new location:
location.href = "index.php?module=Patient_Procedure&action=genMFGPO&pomode=preview";
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
And if you don't care about MSIE 7, it can be even simpler:
Code:
// use AJAX to start creation of the new PDF
var http = new XMLHttpRequest();
http.open("GET","index.php?module=Patient_Procedure&action=genMFGPO'&pomode=create&kindofpo=Z",true);
http.send( );
// ignore the asynch response
// then just change the current popup to the new location:
location.href = "index.php?module=Patient_Procedure&action=genMFGPO&pomode=preview";
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
And if you don't care about MSIE 7, it can be even simpler:
Code:
// use AJAX to start creation of the new PDF
var http = new XMLHttpRequest();
http.open("GET","index.php?module=Patient_Procedure&action=genMFGPO'&pomode=create&kindofpo=Z",true);
http.send( );
// ignore the asynch response
// then just change the current popup to the new location:
location.href = "index.php?module=Patient_Procedure&action=genMFGPO&pomode=preview";
Cool. Yeah, this might work even better. It's an in-house app, and we're moving to IE 9, so no need to code for IE 7.
Quick question, that script that builds the PDF takes a couple of seconds to run. Is there something that I could do so that after the user clicks on the button, they don't click on it again until the whole process runs? I wonder if that's why the window.close was put in.