7 Replies Latest reply: Jan 29, 2013 10:47 AM by sparkyipad
sparkyipad Level 1 Level 1 (0 points)

I have an older HTML application that I am supporting, and admittedly, some of the JavaScript techniques are old, but I don't have the time to re-write the application at this time, it is 100,000's of lines of code.

 

A little background:

  • the code has been unchanged in several years
  • the code works on OSX (10.8.2) in Safari
  • the code works in Win 7 in Safari (5.1.7)

 

Unfortunately, several of my users have upgraded to iOS6 on the iPad and the code does not work in either Safari or Chrome.

 

The application will pop-up a window/tab based on the onChange event of a select element or from the onClick of a button.

 

The onClick from the button does not trigger the Safari "Allow Pop-up", but the onChange event does.

 

Once the pop-up window/tab has been opened (via one of the two methods above), the user makes a selection on screen and clicks a button which (ultimately) triggers a window.opener function.

 

I can not ever get the window.opener function to trigger when the pop-up window was triggered from the onChange (select element).

 

The window.opener will usually (maybe always, but I seem to remember it didn't once or twice) trigger if the pop-up window remains open, but the user manually puts focus on the "opener" window.

 

Again this works (and has worked) for many years on many different browser, unfortunatey, most of my users are now on iPads.

 

Any thoughts or tips would be greatly appreciated.

 

BTW first post, so please be kind.


iPad, iOS 6
  • 1. Re: Safari JavaScript Issues on iPad on with iOS6
    sparkyipad Level 1 Level 1 (0 points)

    While I have not found the issue, I do believe it is related to the fact that the "window.opener" function I am calling  is using at setTimeout("differentFuntion()",0) call to fire another function.

  • 2. Re: Safari JavaScript Issues on iPad on with iOS6
    sparkyipad Level 1 Level 1 (0 points)

    I do have it narrowed down with repeatable code:

     

    parent.html:

                   

     

    child.html

                   

     

    From most major browsers, and I believe Safari on iPad iOS5, the parent.html's function callParent would be triggered.  It is not being triggered in iOS6 on the iPad.  Near as I can tell it is a bug.

  • 3. Re: Safari JavaScript Issues on iPad on with iOS6
    sparkyipad Level 1 Level 1 (0 points)

    Sorry about the HTML, I can't figure out the correct way to enter it.

  • 4. Re: Safari JavaScript Issues on iPad on with iOS6
    etresoft Level 7 Level 7 (24,270 points)

    With 100,000 lines of code in a web app, I don't think many people are going to be too interested. The best anyone could do is give general suggestions.

     

    It sounds like you are opening a new window and then expecting something to happen on the opener in a timer. Because Safari on iOS only loads the current page, that timer isn't going to execute. Pop-ups are really a pain. If you were using CSS, you wouldn't have this problem.

  • 5. Re: Safari JavaScript Issues on iPad on with iOS6
    sparkyipad Level 1 Level 1 (0 points)

    Thank for looking at the post.

     

    I guess my point of stating that it was 100,000's of lines is that I don't have the option of rewriting.

     

    Given that, I was able to narrow the issue.  The pop-up is not the issue, it can call the opener's function no problem, but the opener window's function has a setTimeout that is not triggered and that is the issue.

     

    I'll try to post the sample and reproducible HTML again, this time with [ and ] instead of < and >, maybe that will let it go through.

     

    parent.html:

     

    [html]     [head]         [script language="JavaScript" type="text/javascript"]             [!--             function callParentFromPopup() {                 console.log("start");                 setTimeout(function() {callParent();}, 0);             }             function callParent() {                 console.log("finished");             }             function newWindow() {                 return window.open("child.html","child");             }             // --]         [/script]     [/head]     [body]         [form]             [button type="button" onclick="newWindow();"]newWindow[/button]         [/form]     [/body] [/html]

     

    child.html

     

    [html]     [head]         [script language="JavaScript" type="text/javascript"]             [!--             function updateOpener() {                 var cbf = "window.opener.callParentFromPopup";                 eval(cbf + "();");                 window.close();             }             // --]         [/script]     [/head]     [body]         [form]             [button type="button" onclick="updateOpener()"]updateOpener[/button]         [/form]     [/body] [/html]

     

    Thanks!

  • 6. Re: Safari JavaScript Issues on iPad on with iOS6
    stijn_d Level 1 Level 1 (5 points)

    Hey Sparkyipad, I had a problem just like yours. After using a touch-event the setTimeout wouldn't be triggerd. It did however trigger after a click-event. I've been googleing about this issues for about a day now and found a solution.

     

    Aparently there's been some talk about a bug in the timer-functions in the new mobile safari when it was updated to IOS6 and this solution seems to work for me:

    https://gist.github.com/3798925

     

    In case you are wondering, this is were if found my answer:

    https://github.com/mattbryson/TouchSwipe-Jquery-Plugin/issues/30#issuecomment-91 40015

     

    Hope this helps

  • 7. Re: Safari JavaScript Issues on iPad on with iOS6
    sparkyipad Level 1 Level 1 (0 points)

    iOS 6.1 came out this morning and it appears to resolve this issue.