You can use document.execCommand('selectAll');
. However if the user scrolls the page, you will get the copy/paste menu showing.
This is what I use:
function trySelect(el, evenInactive, select_ios) {
var select = function() {
try {
if (mojo.isTouch && select_ios && core.iosDevice && mojo.isInput(el) && document.execCommand) {
document.execCommand('selectAll');
} else {
el.select();
}
} catch (e) {
}
};
if (el && el.select && !el.disabled && (!el.readOnly || el.selectReadOnly) && mojo.isInput(el)) {
if (evenInactive || mojo.activeElement() === el) {
if (mojo.isTouch && core.webkitVer) { // http://code.google.com/p/chromium/issues/detail?id=32865
setTimeout(select, 0);
} else {
select();
}
}
}
}
That references some internal functions:
- mojo.isTouch - true for a touch device
- core.iosDevice - true for an iOS device
- mojo.isInput - tests for an input element
- mojo.activeElement() - document.activeElement
edit: document.execCommand('selectAll');
should not be used and el.setSelectionRange(0, el.value.length);
used instead. That seems to work fine on iOS5... It might not work on iOS4 (I don't have an iOS4 device to test on).