How can I determine whether the browser supports javascript? _ Javascript tutorial
Source: Internet
Author: User
JavaScript: How can I determine whether the browser supports javascript ?, Javascript tutorials many websites require the client to do a lot of complex work. For example, the client JavaScript is used for Data Validity verification, which requires the JavaScript enabled of the client browser; the Session variable is used to record the identity and other information, browser Cookies are required. Therefore, it is necessary to determine that these options in the user's browser are enabled. On my website, I use a simple string of code to implement these functions. When a user logs on, the system checks. If the user does not match the code, the system does not allow the user to log on. In this article, I will introduce how to write this login page.
We first use JavaScript to create a Cookie and then check whether the Cookie exists. Because we use JavaScript to perform this operation, if the user does not open JavaScript but opens Cookies, we will still get the result that the Cookies are not opened. However, this does not conflict with our requirements. In any case, we need to enable both of them. (If you really only want to know whether Cookies are enabled, but do not care about JavaScript, there is a way to do it. We will discuss it in another article) Determine whether the user has enabled JavaScript, I created a hidden from in html, and then called a JavaScript function in the onload event to change the value of the hidden form. If the value is changed, it indicates that JavaScript is enabled, otherwise, this JavaScript function will not be called. (I wrote the above two functions in one function)
First, we put a hidden form in html and use
...
. (Of course, there can also be username/password from in the middle)
...
If its value is false, the browser does not support JavaScript. Note that the initial value is false. Our JavaScript function will replace this value with true. Write in the BODY as follows:
The content of cc () is as follows:
This program can implement the following functions:
1. When JavaScript is enabled and Cookies are disabled, a warning message is displayed.
2. When JavaScript is disabled, the user cannot directly obtain the check result. (Do not forget to execute the alert JavaScript statement to bring up a warning window, even if the prompt is not displayed), but after the user's from statement is submitted, the background program will find that the value of cookieexists is false, which means JavaScript is disabled. I don't need to talk about anything in the future?
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.