The 55 most common classic tricks in JavaScript

Source: Internet
Author: User

1. oncontextmenu= "Window.event.returnvalue=false" will completely shield the right mouse button

〈table border Oncontextmenu=return (false) 〉〈td〉no〈/table〉 can be used for table

2.〈body onselectstart= "return false" to deselect, prevent copying

3.onpaste= "return false" no paste

4.oncopy= "return false;" oncut= "return false;" Prevent replication

5.〈link rel= "Shortcut icon" href= "Favicon.ico" 〉ie the address bar before switching to your own icon

6.〈link rel= "Bookmark" href= "Favicon.ico" to display your icon in the Favorites folder

7.〈input style= "ime-mode:disabled") off IME

8. Always with frame
〈script language= "JavaScript" 〉〈!--
if (window = = top) Top.location.href = "frames.htm"; Frames.htm for frames page//--〉〈/script〉

9. Prevent people from being frame
〈script Language=javascript〉〈!--
if (top.location! = self.location) top.location=self.location; --〉〈/script〉

10. Web pages will not be saved as
〈noscript〉〈*** src= "/*.html〉"; 〈/***〉〈/noscript〉

11.<input Type=button value= "/View Web page source code
onclick= "window.location =" View-source: "+" http://www.pconline.com.cn ""

12. Confirm 〈a href= "" Javascript:if (Confirm ("Do you want to delete it?") when deleting location= "boos.asp?&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;}
Alert ("top=" +t+ "/nleft=" +l); }
〈/script〉//vbscript
〈script language= "VBScript" 〉〈!--function Getie () Dim t,l,a,b
Set A=DOCUMENT.ALL.IMG1
T=document.all.img1.offsettop l=document.all.img1.offsetleft while a.tagname〈〉 "BODY" set a = A.offsetparent t=t+ A.offsettop L=l+a.offsetleft Wend
MsgBox "Top=" &AMP;T&AMP;CHR (& "left=" &l,64, "get control position" End Function--〉〈/script〉
14. The cursor is the last 〈script language= "JavaScript" 〉function cc () that stops at the text in the textbox
var e = event.srcelement; var r =e.createtextrange ();
R.movestart ("character", e.value.length); R.collapse (TRUE); R.select (); }
〈/script〉
〈input type=text name=text1 value= "123" onfocus= "CC ()")

15. Determine the source JavaScript from the previous page:
Document.referrer

16. Minimize, maximize, close the window
〈object id=hh1 classid= "clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" 〉〈param name= "Command" value= "Minimize" 〉〈/ object〉

Article source: 50 Examples of JavaScript Classics of Baidu Library

The 55 most common classic tricks in JavaScript

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.