Skip to content

Instantly share code, notes, and snippets.

@jimboobrien
Forked from wpscholar/jquery.keboardblock.js
Created September 20, 2017 23:29
Show Gist options
  • Save jimboobrien/9704ffb01025a220c996c0d539181d05 to your computer and use it in GitHub Desktop.
Save jimboobrien/9704ffb01025a220c996c0d539181d05 to your computer and use it in GitHub Desktop.
Prevent the display of the pop-up keyboard on mobile devices
/**
* Using this snippet of code, just add the 'mobile-no-keyboard' class to your input or textarea
* to prevent the keyboard display on most mobile devices. You can just add the 'readonly' attribute,
* but there may be reasons you don't want to on a desktop/laptop machine.
*/
jQuery(document).ready(function($) {
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
$('input.mobile-no-keyboard, textarea.mobile-no-keyboard').attr( 'readonly', 'readonly' );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment