JS prohibits selecting text, copying text code

Source: Internet
Author: User
Tags tagname

JS prohibits selecting text, copying text code

IE has onselectstart this method by setting this method to prevent element text from being selected. Firefox does not have this method, but it can be done through a CSS tutorial or a workaround:

if (typeof (Element.onselectstart)!= "undefined") {
IE prohibits elements from being selected
Element.onselectstart = new Function ("return false");
} else {
Workarounds to prevent elements from being selected under Firefox
Element.onmousedown = new Function ("return false");
Element.onmouseup = new Function ("return true");
}

------------------------
or use Css:div {

-moz-user-select:none;

-webkit-user-select:none;

User-select:none;
}

------------------------

if (document.all)
{
obj.onselectstart= function () {return false;}; For IE
}
Else
{
obj.onmousedown= function () {return false;};

obj.onmouseup= function () {return true;};

}

JS Screen Mouse Right button method
oncontextmenu= "Window.event.returnvalue=false" style= "overflow-y: hidden;
Overflow-x: Hidden "Ajs9 leftmargin=" 0 "topmargin=" 0 "
<body oncontextmenu= "return false" ></body>
<!--prohibit Web page Save as:-->
<noscript><iframe src=*.html></iframe></noscript>
<!--no text selected:-->
<script type= "text/web Effects" >
var omitformtags=["input", "textarea", "select"
Omitformtags=omitformtags.join ("|")
function Disableselect (e) {
if (Omitformtags.indexof (E.target.tagname.tolowercase ()) ==-1)
return False
}
function reenable () {
return True
}
if (typeof document.onselectstart!= "undefined")
Document.onselectstart=new Function ("return false")
else{
Document.onmousedown=disableselect
Document.onmouseup=reenable
}
</script>
<!--disable Right key:-->
<script>
function Stop () {
return false;
}
Document.oncontextmenu=stop;
</script>
1. oncontextmenu= "Window.event.returnvalue=false" will completely screen the right mouse button
<table border Oncontextmenu=return (false) ><td>no</table> available for table
2. <body onselectstart= "return false" > deselect, prevent copying
3. onpaste= "return false" is not allowed to paste
4. oncopy= ' return false; ' oncut= ' return false; ' Prevent replication
5. <link rel= "shortcut icon" href= "Favicon.ico" > IE Address bar before replacing their own icons
6. <link rel= "Bookmark" href= "Favicon.ico" > can display your icon in a Favorites folder
7. <input style= "ime-mode:-disabled" > Close IME
8. Always with the frame
<script language= "JavaScript" ><!--
if (window = top) Top.location.href = "frames.htm"; Frames.htm for frames page
--></script>
9. Prevent a person from being frame
<script language=javascript><!--
if (top.location!= self.location) top.location=self.location;
--></script>
<input type=button value= View Web page source code
onclick= "window.location = ' View-source: ' +
http://www.tonightdream.com/' ";>
12. Confirm upon deletion
<a
Href= ' javascript:if (confirm "Are you sure you want to delete it?") location= "boos.asp tutorial? &areyou= Delete &page=1" ' > Delete </a>
13. Get the absolute position of the control
Javascript
<script language= "JavaScript" >
function Getie (E) {
var t=e.offsettop;
var l=e.offsetleft;
while (e=e.offsetparent) {
T+=e.offsettop;
L+=e.offsetleft;
<!--Right-click Start-->
<script language= "JavaScript" >
<!--
if (window. Event)
Document.captureevents (Event.mouseup);
function Nocontextmenu ()
{
Event.cancelbubble = True
Event.returnvalue = false;
return false;
}
function Norightclick (e)
{
if (window. Event)
{
if (E.which = 2 | | e.which = 3)
return false;
}
Else
if (Event.button = 2 | | event.button = 3)
{
Event.cancelbubble = True
Event.returnvalue = false;
return false;
}
}
Document.oncontextmenu = Nocontextmenu; For ie5+
Document.onmousedown = Norightclick; For all others
-->
</script>
<!--no text selected:-->
<script type= "Text/javascript" >
var omitformtags=["input", "textarea", "select"
Omitformtags=omitformtags.join ("|")
function Disableselect (e) {
if (Omitformtags.indexof (E.target.tagname.tolowercase ()) ==-1)
return False
}
function reenable () {
return True
}
if (typeof document.onselectstart!= "undefined")
Document.onselectstart=new Function ("return false")
else{
Document.onmousedown=disableselect
Document.onmouseup=reenable
}
</script>
<script language= "javascript" type= "Text/javascript" >
<!--
Function key () {
if (Event.shiftkey) {
Window.close ();}
Disable shift
if (Event.altkey) {
Window.close ();}
No Alt
if (Event.ctrlkey) {
Window.close ();}
Suppress CTRL
return false;}
Document.onkeydown=key;
if (window. Event)
Document.captureevents (Event.mouseup);
Swordmaple JavaScript article.
From Www.111cn.net
function Nocontextmenu () {
Event.cancelbubble = True
Event.returnvalue = false;
return false;}
function Norightclick (e) {
if (window. Event) {
if (E.which = 2 | | e.which = 3)
return false;}
Else
if (Event.button = 2 | | event.button = = 3) {
Event.cancelbubble = True
Event.returnvalue = false;
return false;}
}
No right key
Document.oncontextmenu = Nocontextmenu; For ie5+
Document.onmousedown = Norightclick; For all others
-->
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.