JavaScript prohibit right + no choice text JS code mainstream browser compatible

Source: Internet
Author: User

Method 1

var message= "";

///////////////////////////////////

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);d ocument.onmousedown=clickns;}

Else{document.onmouseup=clickns;document.oncontextmenu=clickie;}

Document.oncontextmenu=new Function ("return false")

Method 2

Right-click Start

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

Prevent text from being selected

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

}

Related Article

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.