Skip to content

Instantly share code, notes, and snippets.

@zmiftah
Last active October 11, 2015 05:28
Show Gist options
  • Save zmiftah/56e8879c2f218656598c to your computer and use it in GitHub Desktop.
Save zmiftah/56e8879c2f218656598c to your computer and use it in GitHub Desktop.
jQuery: HTML Protector
//
// From Googling, update: 2012-10-01
//
var disableContextMenu = function(){
return this.each(function(){
$(this).bind('contextmenu', function(){return false})
$(this).mousedown(function(){return false})
$(this).click(function(){return true})
if($.browser.mozilla){ //Firefox
$(this).css('MozUserSelect','none')
}else if($.browser.msie){ //IE
$(this).bind('selectstart', function(){return false})
}
})
}
var enableTextSelect = function(){
var txt = $(':input')
txt.bind('contextmenu', function(){return true})
txt.mousedown(function(){return true})
txt.click(function(){return true})
if($.browser.mozilla){ //Firefox
txt.css('MozUserSelect','text')
}else if($.browser.msie){ //IE
txt.bind('selectstart', function(){return true})
}
return txt
}
var disableRestrictedKey = function(){
return $(this).keydown(function(e){
if(e.ctrlKey){
if(e.keyCode == 65 || e.keyCode == 70 || e.keyCode == 85 || e.keyCode == 83){ /*Ctrl+A; Ctrl+F; Ctrl+U; Ctrl+S;*/
return false
}
}else if(e.altKey){
return false
}
})
}
var disablePrintScreen = function(){
/* PrintScr */
return $(this).keyup(function(e){
if(e.keyCode == 44){
alert("Peringatan...!\nSekedar mengingatkan bahwa web ini berada dibawah perlindungan copyright.");
$("contact").focus();
return false
}
}) && $(this).keypress(function(e){
if(e.keyCode == 44){
alert("Peringatan...!\nSekedar mengingatkan bahwa web ini berada dibawah perlindungan copyright.");
$("contact").focus();
return false
}
}) && $(this).keydown(function(e){
if(e.keyCode == 44){
alert("Peringatan...!\nSekedar mengingatkan bahwa web ini berada dibawah perlindungan copyright.");
$("contact").focus();
return false
}
})
}
/* Extends */
$.extend($.fn.disableRestrictedKey = disableRestrictedKey)
$.extend($.fn.disableContextMenu = disableContextMenu)
$.extend($.fn.enableTextSelect = enableTextSelect)
$.extend($.fn.disablePrintScreen = disablePrintScreen)
$(document).ready(function(){
$(window)
.disableRestrictedKey()
.disableContextMenu()
.disablePrintScreen()
$(document)
.disableRestrictedKey()
.disableContextMenu()
.disablePrintScreen()
$('input[type=txt_username], input[name=txt_password], input:text').click(function(){
$(this).focus()
})
$('#login_form')
.disableRestrictedKey()
.enableTextSelect()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment