Skip to content

Instantly share code, notes, and snippets.

@allex
Created February 22, 2012 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save allex/1880618 to your computer and use it in GitHub Desktop.
Save allex/1880618 to your computer and use it in GitHub Desktop.
Hide the iOs soft keyboard
/* vim: set ft=javascript: */
// Javascript: Hide the iOS soft keyboard
//
// http://uihacker.blogspot.com/2011/10/javascript-hide-ios-soft-keyboard.html
// http://stackoverflow.com/questions/5937339/ipad-safari-make-keyboard-disappear
// -------------------------------------------------------------------------------
// I was having some trouble getting my text input field to relieve itself of focus on the
// iPhone, and after a little searching, I came up with a couple options. It's pretty
// self-explanatory. The 2nd line will de-focus all input fields, and it relies on jQuery.
// I found that calling blur() on the single focused textfield didn't always work. Either
// one of these lines should work independently, but both of them together cannot be stopped!
var hideKeyboard = function() { document.activeElement.blur();
$("input").blur();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment