JavaScript block sample code for page operations _javascript tips

Source: Internet
Author: User

Single JS ban page right menu--Avoid web site information stolen

Copy Code code as follows:

<script type= "Text/javascript" >
function Block (oevent) {
if (window.event)
Oevent=window.event;
if (oevent.button==2)
Alert ("right mouse button not available");
}
Document.onmousedown=block;
</script>

Copying on a Web page is largely accomplished by JavaScript.

<body oncontextmenu= ' return false ' onselectstart= ' return false '
Ondragstart= ' return false ' onbeforecopy= ' return False ' Oncopy=document.selection.empty () onselect= Document.selection.empty () >
-----------------------------------------------
Prevent replication of JS
-----------------------------------------------

Copy Code code as follows:

<script language=javascript1.2>
function Disableselect (e) {
return false} The
Function reenable () {return True
}
file://if ie4+
document.onselectstart=new function ("R Eturn false ")
file://if NS6
if (window.sidebar) {
Document.onmousedown=disableselect
document.onclick= Reenable
}
</SCRIPT>
<script language=javascript type=text/javascript>
<!--
Functi On Mm_reloadpage (init) {   //reloads the window if Nav4 resized
    if (init==true) WI Th (Navigator) {if (appname== "Netscape") && (parseint (appversion) ==4)) {
      Document. Mm_pgw=innerwidth; Document. Mm_pgh=innerheight; Onresize=mm_reloadpage; }
    else if (innerwidth!=document. MM_PGW | | Innerheight!=document. MM_PGH) location.reload ();
}
Mm_reloadpage (true);
//-->
</SCRIPT>

-------------------------------------------------------
Prevent the download of JS
-------------------------------------------------------
<noscript><iframe src= "" ></iframe></noscript>
--------------------------------------------------------

The following is the right key to prevent JS:

Copy Code code as follows:

<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>

<title>css prohibit selection and replication </title>
<meta http-equiv= "Content-type" content= "text/html;charset=gb2312" >
<style>
body{
-moz-user-select:none;
Hutia:expression (This.onselectstart=function () {return (FALSE)});
}
</style>
<body>
Here is the page content, try you can copy?
</body>


application Example:
Copy Code code as follows:

<title>js Control Page </title>
<script language= "javascript" type= "Text/javascript" >
Prevent users from using mail (hide right menu)
Document.oncontextmenu = function Forbidrightkey () {
Window.event.returnValue = false;
}
Prevent users from using mail (prompts the user to disable the right key)
function block () {
var oevent;
if (window.event)
Oevent = window.event;
if (Oevent.button = 2)
Alert ("right mouse button not available");
}
Document.onmousedown = Block;

When the user presses the AltF4, prompts to close the window information
function AltF4 () {
if (window.event.altKey && window.event.keyCode = 115) {
Window.close ();
}
}
Alt left mouse button to make the shortcut key select the content in the text box to call the way <body onkeydown= "altF4 ();" >
function Gettxtselect (Eventcontrol) {
if (Eventcontrol.altkey) {
document.getElementById ("Txt1"). Select ();
}
}

function Cleartxtbyinput () {
document.getElementById ("Txtcontent"). Value = "";
}

function Filltxtbyinput () {
document.getElementById ("Txtcontent"). Value = "Input search condition";
}
Disables a few keys on the keyboard to invoke onkeydown= "Forbidkeys ();"
function Forbidkeys () {
var content = Window.event.keyCode;
if (content >= && content <= 68) {
Window.event.returnValue = false;
} else {
Window.alert (content);
}
}

Prohibit copying of Web page content <body oncopy= "forbidcopy ();" >
function Forbidcopy () {
Window.event.returnValue = false;
Window.clipboardData.setData ("Text", "");
Alert ("Prohibit copying Web content!") ");
}

Set up copy content to append the URL of this website
function Setcopycontent () {
Window.event.returnValue = false;
var content = Document.title + "/r/n";
Content + + document.getElementById ("Txt1"). Value + "/r/n";
Content + = "This resource comes from" + this.location.href;
Window.clipboardData.setData (' Text ', content);
Alert ("Copy successful, paste on your qq/msn to recommend to your friends");
}

Disable refreshing of F5 and Ctrl+f5
function Forbidfreshpage () {

            if (Window.event.ctrlKey && Window.event.keyCode = 116) | | Window.event.keyCode = = 116) {
                Window.event.keyCode = 0;
               Window.event.returnValue = false;
          }
       }
        document.onkeydown = forbidfreshpage;
       //Masking JS error
        function Killerrors () {
            return true;
       }
        window.onerror = Killerrors;


</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<input id= "Txt1" type= "text" value= "Hello world!" onclick= "Gettxtselect (event)"/>
<input type= "button" value= "Copy the value in the text box" onclick= "setcopycontent ();"/>
<input id= "txtcontent" value= "Enter search terms style=" Color:aqua "onclick=" cleartxtbyinput (); " Onblur= "Filltxtbyinput ();"/>
<p>content</p>

</div>
</form>
</body>

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.