Skip to content

Instantly share code, notes, and snippets.

@acobster
Created March 7, 2015 00:12
Show Gist options
  • Save acobster/07db08d5f507d32c3786 to your computer and use it in GitHub Desktop.
Save acobster/07db08d5f507d32c3786 to your computer and use it in GitHub Desktop.
Make all text un-selectable - CSS3 with Javascript fallback
<style>
body {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>
<script type="text/javascript">
window.onload = function() {
var body = document.getElementsByTagName('body');
disableSelection(body[0]);
};
function disableSelection(element) {
if (typeof element.onselectstart != 'undefined') {
element.onselectstart = function() { return false; };
} else if (typeof element.style.MozUserSelect != 'undefined') {
element.style.MozUserSelect = 'none';
} else {
element.onmousedown = function() { return false; };
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment