hadoob024 Posted September 24, 2012 Share Posted September 24, 2012 In a popup, I have a button. Here's how I defined the button: <input type="button" name="generatePO" value="Z-PO" onclick="Javascript:window.close();window.location='index.php?module=Patient_Procedure&action=genMFGPO'&pomode=create&kindofpo=Z';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')"> 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: <input type="button" name="generatePO" value="Z-PO" onclick="Javascript:window.location='index.php?module=Patient_Procedure&action=genMFGPO'&pomode=create&kindofpo=Z';window.location.replace('index.php?module=Patient_Procedure&action=genMFGPO&pomode=preview');"> For some reason though, the window.open() doesn't get executed unless I click on the button twice. Can't think of how to fix this for IE. Thoughts??? Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/ Share on other sites More sharing options...
Christian F. Posted September 24, 2012 Share Posted September 24, 2012 First of all, you should not use javascript: in the intrinsic event handler; It has no place there, and is plain wrong. In fact, that particular piece of code should never be used, as it was a hack from way back when JS was new. Might even be this that causes you problems. You'll also want to move the code into a function, and call that function in the event handler. Instead of trying to jam all of that code into the HTML tag, not only will it help make the code a lot easier to read, but it'll make things a lot easier to maintain as well. As for your original code: Is there any particular reason you decided to close the window running the code first, before doing everything else? Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/#findComment-1380660 Share on other sites More sharing options...
hadoob024 Posted September 24, 2012 Author Share Posted September 24, 2012 First of all, you should not use javascript: in the intrinsic event handler; It has no place there, and is plain wrong. In fact, that particular piece of code should never be used, as it was a hack from way back when JS was new. Might even be this that causes you problems. That did it! My original code still doesn't run properly (the window.open() never executes), but that rewritten one does run! You'll also want to move the code into a function, and call that function in the event handler. Instead of trying to jam all of that code into the HTML tag, not only will it help make the code a lot easier to read, but it'll make things a lot easier to maintain as well. That's the plan. Just trying to get it to work first before tidying up stuff. As for your original code: Is there any particular reason you decided to close the window running the code first, before doing everything else? Nope, no particular reason. I didn't know about window.location.replace(), so I thought I had to do it that way (close window, generate PDF, open new window showing remaining PDF's that can be created). Any thoughts about why the first way doesn't work in IE, but works in Firefox? Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/#findComment-1380664 Share on other sites More sharing options...
Christian F. Posted September 24, 2012 Share Posted September 24, 2012 I suspect it's because IE terminates any scripts running when the window closes, which is why I asked the last question. Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/#findComment-1380674 Share on other sites More sharing options...
hadoob024 Posted September 24, 2012 Author Share Posted September 24, 2012 I suspect it's because IE terminates any scripts running when the window closes, which is why I asked the last question. First off, thanks for the help! That's what I thought too, but it's weird because in my original code, the window.location does run (because the PDF gets generated). It's just the window.open that never executes. And this is only in IE. Everything runs through properly in Firefox. Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/#findComment-1380676 Share on other sites More sharing options...
Christian F. Posted September 24, 2012 Share Posted September 24, 2012 I don't know then, as I don't have IE on my computer. I'd recommend using a debug tool to trace the execution though, might shed some light. You're welcome, Glad I could help. Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/#findComment-1380677 Share on other sites More sharing options...
hadoob024 Posted September 24, 2012 Author Share Posted September 24, 2012 I don't know then, as I don't have IE on my computer. I'd recommend using a debug tool to trace the execution though, might shed some light. You're welcome, Glad I could help. Thanks! Yeah, I'm so used to Firefox/Firebug and Chrome/Chrome Developer Tools. Haven't had a chance to really play around with IE and its developer tools. Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/#findComment-1380679 Share on other sites More sharing options...
kicken Posted September 24, 2012 Share Posted September 24, 2012 That's what I thought too, but it's weird because in my original code, the window.location does run (because the PDF gets generated). It's just the window.open that never executes. And this is only in IE. Everything runs through properly in Firefox. It is probably just a race-condition where the window.close starts IE's cleanup procedures to close the page but leaves the script running. IE gets in another statement or two of code before the cleanup process kills the scripting engine. Regardless of if it works or not in other browsers, what your attempting to do is fundamentally wrong. What you should be doing is either 1) Load the URL to regenerate the PDF by assigning it to window.location, and after the PDF generation is done have it do a header redirect to the PDF viewing page that your currently trying to open -or- 2) Run the PDF generation process by loading that URL with XMLHttpRequest and wait for message that is has completed. Once complete, load the PDF viewing page. At no point should you be trying to close and re-open a window. Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/#findComment-1380682 Share on other sites More sharing options...
hadoob024 Posted September 24, 2012 Author Share Posted September 24, 2012 It is probably just a race-condition where the window.close starts IE's cleanup procedures to close the page but leaves the script running. IE gets in another statement or two of code before the cleanup process kills the scripting engine. Regardless of if it works or not in other browsers, what your attempting to do is fundamentally wrong. What you should be doing is either 1) Load the URL to regenerate the PDF by assigning it to window.location, and after the PDF generation is done have it do a header redirect to the PDF viewing page that your currently trying to open -or- 2) Run the PDF generation process by loading that URL with XMLHttpRequest and wait for message that is has completed. Once complete, load the PDF viewing page. At no point should you be trying to close and re-open a window. Cool! Thanks for the tips! Quick follow-up, I can do a couple of window.location calls back to back, right? Christian F. resolved my issue by telling me to remove the "Javascript:" from my onclick call, and that seemed to work. Yeah, I'm more of a backend programmer than a front-end developer. This issue was just kinda dropped into my lap the other day Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/#findComment-1380711 Share on other sites More sharing options...
kicken Posted September 25, 2012 Share Posted September 25, 2012 Quick follow-up, I can do a couple of window.location calls back to back, right? Not really no. It'll be like the window.close thing. Any action which would cause you to essentially "leave the page" (ie, closing the window, re-direct, document.open, etc) should be treated as a final action because it will at some point cause the scripting engine to be killed. Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/#findComment-1380725 Share on other sites More sharing options...
hadoob024 Posted September 25, 2012 Author Share Posted September 25, 2012 Not really no. It'll be like the window.close thing. Any action which would cause you to essentially "leave the page" (ie, closing the window, re-direct, document.open, etc) should be treated as a final action because it will at some point cause the scripting engine to be killed. Quick question then, 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. Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/#findComment-1380798 Share on other sites More sharing options...
Christian F. Posted September 25, 2012 Share Posted September 25, 2012 Yes, disable the button and show a "working" placeholder image. Just like any other AJAX-enabled website does it. Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/#findComment-1380808 Share on other sites More sharing options...
hadoob024 Posted September 25, 2012 Author Share Posted September 25, 2012 Yes, disable the button and show a "working" placeholder image. Just like any other AJAX-enabled website does it. Perfect! That works! Quote Link to comment https://forums.phpfreaks.com/topic/268752-windowopen-not-getting-executed-in-ie-working-in-firefox/#findComment-1380872 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.