The Verification Code cannot be refreshed in IE7 or ff.

Source: Internet
Author: User
The dynamic verification code is used in the logon window.

 

Code:

 

Corresponding JS

Function refreshcode (){
Document. getelementbyid ("checkcode"). src = "authimg"; (or new date ())
}

 

Result:

The verification code image in IE 6 can be refreshed, but cannot be refreshed in IE 7 and ff.

Cause:

After analysis, because the SRC specified by JS is the same as the SRC of the original image, the refreshing mechanism of IE 6 is different from that of IE 7 and FF (this page is easily cached by IE, therefore, when you click the verification code image, IE7 and FF only display the cached page to the client, rather than re-going to the server to retrieve the new page), leading to the failure to refresh IE7 and ff.

 

Solution:

Pass a parameter to the SRC address ("authimg" in the Code) and pass different parameters. The browser considers that the SRC of IMG has changed and then retrieves a new page from the server, instead of reading the cache, a new verification code is generated.

 

Solution:

You can use the Javascript. Math. Random () function (returns a pseudo-random number between 0 and 1, which may be 0, but always less than 1, [0, 1 )).

 

Improved code:

Function refreshcode (){
Document. getelementbyid ("checkcode"). src = "authimg? "+ Math. Random ();
}

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.