Skip to content

Instantly share code, notes, and snippets.

@nathany
Created May 4, 2010 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathany/389625 to your computer and use it in GitHub Desktop.
Save nathany/389625 to your computer and use it in GitHub Desktop.
///////////////////////////////////////////////////////////////////////////////
//
// jquery.protect.js
// Copyright (c) 2010 Yardstick Software
//
// This plugin allows you protect a page from selection/copying the text.
//
// Doesn't do anything about Print Scrn, Save As...
//
///////////////////////////////////////////////////////////////////////////////
(function($) {
$.fn.protect = function() {
// prevent the text from being copied (Firefox, Safari) (IE doesn't fire when targetting the document)
$(document).bind('copy', function(e){ return false; });
// Prevent the text from being selected (handles most things, but not Ctrl+A, Ctrl+C in Firefox, Safari, which above handles)
$('body').css("-moz-user-select", "none")
$().attr("unselectable", "on")
.bind("selectstart.ui", function() {
return false;
});
return this;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment