Comments on: Disable Text Selection With jQuery https://www.chris-barr.com/2009/02/disable_text_selection_with_jquery/ Photo/Dev/Design Thu, 13 Dec 2018 13:32:15 +0000 hourly 1 https://wordpress.org/?v=4.4.20 By: berry https://www.chris-barr.com/2009/02/disable_text_selection_with_jquery/#comment-6712 Mon, 15 Feb 2016 08:47:20 +0000 http://URLTOYOURWORDPRESS.com/?p=142#comment-6712 Nice tutorial very helpful there is another complete tutorial to make text unselected using css on talkerscode.com http://talkerscode.com/webtricks/disable-text-selection-in-webpage-using-css.php

]]>
By: Joshuasm32 https://www.chris-barr.com/2009/02/disable_text_selection_with_jquery/#comment-400 Sat, 08 Feb 2014 06:10:06 +0000 http://URLTOYOURWORDPRESS.com/?p=142#comment-400 In case you are interested, here is a method in which to disable all text selection (including clicking text 3 times), the usage of CTRL shortcuts in older browsers, and right-clicks using pure JS:

[html]
[head]
[script]
function disableselect(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function (“return false”)
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
[/script]
[body onKeyPress=”return disableCtrlKeyCombination(event);” onKeyDown=”return disableCtrlKeyCombination(event);”]
var message=”Sorry, right-click has been disabled”;
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function(“return false”);
function disableCtrlKeyCombination(e)
{
var forbiddenKeys = new Array(‘a’,‘n’,‘c’,‘x’,‘v’,‘j’,‘w’,’p’,’u’);
var key;
var isCtrl;
if(window.event)
{
key = window.event.keyCode;
if(window.event.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
else
{
key = e.which;
if(e.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
if(isCtrl)
{
for(i=0; i<forbiddenKeys.length; i++)
{
if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
{
alert(‘Key combination CTRL + ‘+String.fromCharCode(key) +’ has been disabled.’);
return false;
}
}
}
return true;
}
[/script]
[p]Try Selecting Me :P[/p]
[/body]
[/html]

It is also possible to include Linux freeware to disable the selection of options such as print from a toolbar.

]]>
By: Joshuasm32 https://www.chris-barr.com/2009/02/disable_text_selection_with_jquery/#comment-399 Sat, 08 Feb 2014 06:06:25 +0000 http://URLTOYOURWORDPRESS.com/?p=142#comment-399 Ugh. {body onKeyPress=”return disableCtrlKeyCombination(event);” onKeyDown=”return disableCtrlKeyCombination(event);” }

]]>
By: Joshuasm32 https://www.chris-barr.com/2009/02/disable_text_selection_with_jquery/#comment-398 Sat, 08 Feb 2014 06:05:20 +0000 http://URLTOYOURWORDPRESS.com/?p=142#comment-398 My bad – html is disabled. The first halve is under the head, and the second in the body. Include this in your body element:

]]>
By: Joshuasm32 https://www.chris-barr.com/2009/02/disable_text_selection_with_jquery/#comment-397 Sat, 08 Feb 2014 06:00:16 +0000 http://URLTOYOURWORDPRESS.com/?p=142#comment-397 In case you are interested, here is a method in which to disable all text selection (including clicking text 3 times), the usage of CTRL shortcuts in older browsers, and right-clicks using pure JS:

function disableselect(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function (“return false”)
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}

var message=”Sorry, right-click has been disabled”;
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function(“return false”);
function disableCtrlKeyCombination(e)
{
var forbiddenKeys = new Array(‘a’,‘n’,‘c’,‘x’,‘v’,‘j’,‘w’,’p’,’u’);
var key;
var isCtrl;
if(window.event)
{
key = window.event.keyCode;
if(window.event.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
else
{
key = e.which;
if(e.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
if(isCtrl)
{
for(i=0; i<forbiddenKeys.length; i++)
{
if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
{
alert(‘Key combination CTRL + ‘+String.fromCharCode(key) +’ has been disabled.’);
return false;
}
}
}
return true;
}

Try Selecting Me :P

It is also possible to include Linux freeware to disable the selection of options such as print from a toolbar.

]]>
By: vyshak https://www.chris-barr.com/2009/02/disable_text_selection_with_jquery/#comment-393 Sat, 04 Jan 2014 06:19:25 +0000 http://URLTOYOURWORDPRESS.com/?p=142#comment-393 Thank you, its worked.

]]>
By: Bruno Santana https://www.chris-barr.com/2009/02/disable_text_selection_with_jquery/#comment-375 Fri, 04 Oct 2013 16:13:28 +0000 http://URLTOYOURWORDPRESS.com/?p=142#comment-375 You, sir, are an adorable person for sharing this. Thanks!!!

]]>
By: roman https://www.chris-barr.com/2009/02/disable_text_selection_with_jquery/#comment-158 Mon, 25 Jun 2012 07:35:36 +0000 http://URLTOYOURWORDPRESS.com/?p=142#comment-158 Nice script. Works very well.

]]>
By: Antony https://www.chris-barr.com/2009/02/disable_text_selection_with_jquery/#comment-157 Tue, 15 May 2012 08:40:22 +0000 http://URLTOYOURWORDPRESS.com/?p=142#comment-157 Thank you very much. Your script is work well.

]]>
By: Constantin https://www.chris-barr.com/2009/02/disable_text_selection_with_jquery/#comment-156 Thu, 19 Jan 2012 09:57:15 +0000 http://URLTOYOURWORDPRESS.com/?p=142#comment-156 Very useful, thanks!

]]>