Disable content selection on web page using jquery

In previous article we learned how to prevent our blog content from copying by disabling right click on web page. Now in this article i will show you how to disable content selection on web page using jQuery.

To  disable content selection on web page follow these steps

Include jQuery in your web page

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

Insert following code in head section

$(function(){
$(document).attr('unselectable','on')
.css({'-moz-user-select':'-moz-none',
'-moz-user-select':'none',
'-o-user-select':'none',
'-khtml-user-select':'none',
'-webkit-user-select':'none',
'-ms-user-select':'none',
'user-select':'none'
}).on('selectstart', function(){return false; });
});

Demo

Published by Sunny

A Mechanical engineer by education and web developer by passion and profession. He lives in Lucknow, India. Currently earning his livings by hitting keyboad. ;)

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *