Jump to content

Window.open() Not Getting Executed In Ie (Working In Firefox)


hadoob024

Recommended Posts

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???

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.