1

all!

I'm having an issue with parent/child window communication on the stock Android 'Browser' browser. Safari, Chrome, Firefox, IE(!!!), iOS, all good! Android v4.1.1, not so much.

The flow:

  1. From the parent, I open a child window, and add a loop to listen for the child window to close.
  2. Child window closes, parent is notified.
  3. Parent clears the loop, calls the handler.

Easy, right?

The problem: Android can call the window.close() from the child, but the parent is unaware of the close event, ie, step 3 never happens. Perhaps javascript is suspended in the parent while a child window is opened? Javascript is indeed running in the parent window. Is there a definitive fix or workaround for this problem?

My CoffeeScript:

openTwitterAuthWindow: (authURL) =>
    @twitterWindow = window.open(authURL, "_blank", "width=550,height=420")
    @checkInterval = window.setInterval(@checkChildWindow, 500)

checkChildWindow: () =>
    if (@twitterWindow && @twitterWindow.closed)
        alert("Excelsior!") # <-- Not called, unfortunately
        window.clearInterval(@checkInterval)
        @twGetLoginStatus()

Only javascript inside the child window:

<script type="text/javascript">
    window.close();
</script>

Thanks in advance!

4

1 回答 1

0

正如您所建议的,父窗口似乎不知道子窗口何时关闭。但是,如果子窗口已关闭,则父窗口对它的引用此时将为空,因此以下内容应在 Android 中工作:

openTwitterAuthWindow: (authURL) =>
    @twitterWindow = window.open(authURL, "_blank", "width=550,height=420")
    @checkInterval = window.setInterval(@checkChildWindow, 500)

checkChildWindow: () =>
    if (!@twitterWindow || @twitterWindow.closed)
        alert("Excelsior!")
        window.clearInterval(@checkInterval)
        @twGetLoginStatus()
于 2013-06-19T09:37:09.250 回答