WeChat browser Javascript cannot use window. location. reload () to refresh the page, location. reload

Source: Internet
Author: User

The browser Javascript cannot use window. location. reload () to refresh the page, location. reload

The scenario is like this. The page has an ajax request during initialization. There is a button on the page and the window is executed when clicked. location. reload (). Normally, after reload (), the page still sends a request to the background. However, in the android browser, after reoad, the request is always the data requested when the page is opened for the first time. It can be understood that the request is cached, but it is not tested or determined whether the request is cached.

Solution:Use window. location. href = "window. location. href + random number" to replace window. location. reload (). Remember to add a random number, otherwise it will not work. Of course, you can also use a tag a and then set href = "window. location. href + random number ".

Further, you can set this parameter only for the browser, so you have to determine whether the browser is used. You can use window. navigator. userAgent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13F69 MicroMessenger/6.3.16. Determine whether the browser is built based on the keyword MicroMessenger. The judgment function is as follows:

Function isWeiXin () {var ua = window. navigator. userAgent. toLowerCase (); if (ua. match (/MicroMessenger/I) = 'micromessenger ') {return true;} else {return false ;}}

The above is all about the content of this article. For more information about the JavaScript syntax, see: JavaScript reference tutorial and JavaScript code style guide. I also hope you can provide more support.

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.