How to set focus on top item?

How do you set focus in Safari on iOS, or determine that you can't?

  • Calling .focus() on a textbox doesn't work onload in Safari on iOS (), is there a workaround? I tried faking click or mousedown events to no avail. What's worse is, .focus() will both trigger onfocus event handlers attached to the textbox and set document.activeElement to the textbox, even if the event is ignored like onload. Is there a way to check if the textbox is actually focused, or is there any other possible workaround short of sniffing for Safari on iOS onload and assuming the .focus() won't work? I'd hate to resort to browser sniffing, if future versions of Safari on iOS fix this or another mobile browser that doesn't have this bug spoofs the Safari on iOS User Agent String, the assumption will be wrong.

  • Answer:

    Have not tried but shouldn't you be trying to detect a touch device and use its specific events? I think you should go from "fixing a problem" mode to "supporting a feature" mode. The fact that only iOS has a problem with this doesn't mean you're doing it right on all the other devices. I mean the next thing you'll notice is that the next version of Android or WP removes the focus() support. And if you think of it. On a desktop computer, there's only one cursor. There's always going to be one single element in focus. Because there's only one cursor. But on a touch screen device, well, there can be 10-point multi-touch screen. Which of these 10 points is in focus? One good library for detecting client features is Modernizr. if (Modernizr.touch) { alert('Touch Screen'); } else { alert('No Touch Screen'); } http://www.hongkiat.com/blog/detect-touch-device-modernizr/

Jani 'Jassi' Hyytiäinen at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.