What is the Mobile Safari event for the on-screen

2019-06-25 14:28发布

问题:

I'd like to run a $('html, body').animate({ scrollTop: 0 }, 0); anytime the on-screen keyboard is closed in my iPad web app. I've tried with .blur(); but that causes problems if the user focuses on the next or previous field directly from the on-screen keyboard.

Does closing the keyboard trigger an event of any sort? That would be the most stable route for me to go.

回答1:

Switched the event to blur() and it seems to work a lot better with the iPad, Playbook still does some strange things. I don't think the event firing is quite there for the Playbook yet.

// Check for dirty inputs
$("form :input").blur(function()
{
    // FORCE THE PAGE BACK TO THE TOP   
    $('html, body').animate({ scrollTop: 0 }, 0);           
});


回答2:

I tried checking for dirty inputs and it seems the selector fires after the keyboard is closed, so I put your code in there and it worked like a charm:

// Check for dirty inputs
$("form :input").change(function()
{
    // DO OTHER HOUSE KEEPING HERE

    // FORCE THE PAGE BACK TO THE TOP   
    $('html, body').animate({ scrollTop: 0 }, 0);           
});

This is working on ipad without any quirks. On the Playbook it looks like the user has to select the "return" button then close the keyboard for the change function to fire correctly.