I do not hope, but I will ask just in case.
I would like to be able to use JavaScript to open the select element in mobile Safari for iPhone / iPad.
A broad Google / Qaru search shows that many people would like to do this in browsers in general, but it is not supported (why not, I wonder?). Various hacks have been proposed by calling focus() on the select element and changing its size property to make more option elements visible or to create a fully mocked select element with <div> and <ul> elements. However, I would like to use my own browser to control the iPad and iPhone.
Interestingly, maybe someone might know about Apple's own WebKit method to do this. It will be something like:
var myselect = document.getElementsByTagName("select")[0]; myselect.open();
As a bonus, it would also be useful to know a logical property that says whether the selection item is currently open / active or not (i.e. not only whether the item has focus). I know that I can fix this by tracking the click and changing events, but a simple property would be useful.
Desired Thinking?
UPDATE:
I donβt have an answer yet, but I found that the mousedown simulation successfully opens a select item in Google Chrome, but not iPad or Firefox, and so on:
function simulateMouseEvent(eventName, element) { var evt = document.createEvent("MouseEvents"); evt.initMouseEvent(eventName, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); element.dispatchEvent(evt); } simulateMouseEvent("mousedown", select);
UPDATE:
I asked a related but different (and also unanswered!) Field selection question here: Is there a DOM event that fires when the HTML select element is closed?
javascript html ios iphone ipad
Premasagar May 23 '11 at 12:33 2011-05-23 12:33
source share