Generally, few users want to disable javascript. Therefore, JavaScript, Ajax, cookie, and other technologies are more or less used to achieve good user experience and webpage effects.
However, the existing Web attacks often use these mobile code (JavaScript, Cookie, Flash, Java applets, ActiveX, etc.) to attack clients for illegal purposes. Therefore, some users with high security awareness use the functions provided by the browser to disable or shield JS and cookie.
Therefore, it is necessary to determine whether the client Javascript is disabled and prompt the user to enable the JavaScript function. See the following code:
Java code
- <Div id = "nojs"> you disabled JavaScript. </Div>
- <Div id = "yesjs"> body </div>
- <SCRIPT>
- VaR nojs = Document. getelementbyid ("nojs ");
- Nojs. classname = "close ";
- // Close the style code. Close {display: none ;}
- </SCRIPT>
<Div id = "nojs"> you disabled JavaScript. </Div> <Div id = "yesjs"> body </div> <SCRIPT> var nojs = document. getelementbyid ("nojs"); nojs. classname = "close"; // close the style code. close {display: None ;}</SCRIPT>
The principle of this code is very simple, that is, if the javascrpt code is executed, the DIV with the ID of nojs is hidden, otherwise it is displayed.
The following code uses JavaScript to determine whether the cookie function is Enabled:
JS Code
- <SCRIPT>
- Function cookieenable (){
- VaR result = false;
- If (navigator. cookiesenabled) return true;
- Document. Cookie = "testcookie = yes ;";
- VaR cookieset = Document. Cookie;
- If (cookieset. indexof ("testcookie = yes")>-1) Result = true;
- Document. Cookie = "";
- Return result;
- }
- If (! Cookieenable ()){
- Alert ("sorry, your browser's cookie function is disabled, Please enable ");
- }
- </SCRIPT>
<SCRIPT> function cookieenable () {var result = false; If (navigator. cookiesenabled) return true; document. cookie = "testcookie = yes;"; var cookieset = document. cookie; If (cookieset. indexof ("testcookie = yes")>-1) Result = true; document. cookie = ""; return result;} If (! Cookieenable () {alert ("sorry, your browser's cookie function is disabled. Please enable") ;}</SCRIPT>
The above method is not the only solution or the best solution. It depends on the actual situation. In short, I think we should improve the availability and ease-of-use of the website. We should start by disabling JS, cookies, and so on, so that cookies and JS cannot affect the normal functions of the website.