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
Related Q & A:
- How to set focus to Fieldmanager in blackberry?Best solution by Stack Overflow
- How come I can't get into the chat rooms?Best solution by answers.help.ea.com
- Why can't I set my messenger mobile?Best solution by Yahoo! Answers
- Why can't I set my monitor to a higher resolution?Best solution by Super User
- I can't focus at all in school?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.