JavaScript simple Tricks

Source: Internet
Author: User

1. Get a random number in a specific range
var x = Math.floor (Math.random () * (Max-min + 1)) + min;

2. Let the page automatically refresh once
function () {    if (location.href.indexOf (' #reloaded ') = = = 1)        {= location.href + "#reloaded ";        Location.reload ();    }}

3. Get the page back and refresh
Window.history.go ( -1); Window.location.reload ()

4. The form has only one input of the Enter submit questionIf you press ENTER when there is only one INPUT element in the form, the input element becomes the Submit type submission form. The blocking method is to add an input inside the form and hide it.    5. Determine if the image in the Web page is loaded, and call the method after the loading is complete
if (img.complete) {    function() {        // do something ...   Else {    function() {        // do       Something ...     };}

6. Determine if the browser is IE
if (Navigator.userAgent.indexOf (' MSIE ') >-1) {    alert (' you are using IE browser! ')}//  Msie/chrome/firefox/opera

7. Page function Processing
//Screen Right-click menuDocument.oncontextmenu =function() {return false; } //Prohibit selectionDocument.onselectstart =function() {return false; } //Prohibit copyingdocument.getElementsByTagName (' body ') [0].oncopy =function() {return false; } //Prohibit clipping<input type= "text" oncut= "return false":>//Prevent  //Prohibit paste<input type= "text" onpaste= "return false":>//prevent the current page from being imported into an IFRAMEif(Top.location!==self.location) {top.location=self.location;} //determine if the current page has an IFRAMEif(Window!==top) {Console.log (' Current page has iframe '); } //determine the source of the current page (from which page opens or jumps)Document.referrer

JavaScript Simple tips

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.