0

I am having an issue in firefox. My research so far is telling me that there is not really a reliable way to deal with my problem, but I am wanting to ask just in case.

I have the following javascript/jquery to open a new window triggered by pressing a button on my page:

alipayTransactionModalTrigger.click(function() {
     NIWindow=window.open("<!--ALIPAY_CONF_REDIRECT_URL-->", "NI payment");
     alipayTransactionModal.dialog("open");
  });

In Chrome and Firefox, this opens a new frame, and the frame gets focus. This is fine. However, if a user leaves this new frame open, and comes back to my original page. They are able to hit the button to trigger this event again. If this occurs, the new frame reloads as it should, but in Firefox the new frame does NOT pull focus this on this refresh. I am not sure why it would pull focus on the initial new frame load, but not pull focus if the frame is refreshed with the same event trigger. I haven't had the courage yet to check this in IE...

Is this one of those things that you cannot reliably control? Or is there a way to do this? Note, I have tried using NIWindow.focus() after the initial window open line of code above. No luck.

I believe I read something about possibly using alerts, but I was not sure how to implement the described solution, and I read that it was a bit of a hacky solution.

I could just always open a new window "_blank", and that would assure focus, but the newly opened frame url uses parameters that are based on the parent window. I have no access to that code, so there is no way for me to add checks to make sure data matches up, until I get a response back from this redirect

mkohanek
  • 69
  • 1
  • 10

1 Answers1

0

Give each new window a new name. Do you have a reason for reusing the "NI payment" name?.

If your code has dependencies on this window name you should consider passing the window reference (NIWindow) directly instead of the name. Injecting/passing your dependencies instead of relying on a magic super global is a better approach in general.

Halcyon
  • 57,230
  • 10
  • 89
  • 128
  • Well, the variable in this lies in the url parameters used in window.open. For example, say initially I send the user to www.test.com?test=123 but the user comes back to the initial page, and changes something, which causes the new url to look like this www.test.com?test=246 If the user left the first new window open, and decides to use that one instead of the second newly opened window, the site uses test=123 instead of test=246 The site the user is being sent to is a paypal type of site, so you can see how that could be problematic. I have logic to check for this later of course just in case – mkohanek Feb 01 '13 at 16:24
  • I think you should be able to rewrite your code to use the window dependency. You can redirect a user by `NIWindow.location.href = "[next page]"` from the calling window. – Halcyon Feb 01 '13 at 16:30
  • That accomplished the same thing my code above does - I call `window.open` initially to open the window. Then if the user tries again , I use `NIWindow.location.href`, but that just reloads the window without focusing it - the focus remains on the parent window. – mkohanek Feb 01 '13 at 16:50
  • No, you're not doing it right, you need to make a new window each time the user 'tries again'. – Halcyon Feb 01 '13 at 16:51
  • Maybe I am misunderstanding. You mean something like this? `NIWindow=window.open("", "NI payment"); NIWindow.location.href = ""; alipayTransactionModal.dialog("open");` If so, I tried that as well with the same result. -sorry I can't seem to get the formatting any better than that in the comment reply section – mkohanek Feb 01 '13 at 21:25