I have a search input on an HTML 5 page that I need to work in multiple browsers:
<input type="search" placeholder="type here..." />
I detect whether the browser supports search by seeing whether the browser rendered it as a search input or a regular text one:
var supportsHtml5Search = !!(inputDomElement.type !== text ); if (supportsHtml5Search) { inputDomElement.addEventListener( search , searchFunction); } else { // This browser doesn t support onsearch event, so handle keyup instead inputDomElement.addEventListener( keyup , searchFunction); }
This worked fine - Chrome and Safari used the onsearch event (which also helpfully fires when they hit the clear X icon) and IE used the keyup event (with some additional checks not shown here).
However that seems to be broken in IE10, which displays a search exactly the same as an <input type="text" /> (like IE9 and below) and returns search as the type (like Chrome/Webkit), but doesn t fire the onsearch event.
Is there a better way to detect search input support?
What is the best way to sniff for this feature s support?