This article introduces how to prevent Internet Explorer 6, Internet Explorer 7, and Internet Explorer 8 from reading cookies. For more information, see.
Cause Analysis
Normally, JavaScript code has been written, and all tests have passed. IE10 rendering mode IE7, 8, and 9 has also passed the test. At this time, the customer reported that there was a problem with IE8 under XP: the default skin cannot be displayed during the First Login, and the skin after the switch is clicked and refreshed cannot be displayed after the switch.
The cookie is used to determine whether to display the default skin or the skin selected by the previous user. Therefore, the cookie cannot be read. Start the VMware Virtual Machine, open the IE8 and IE Developer ToolBar tools for debugging, and find that the cookie has been successfully created after the click, but the Code cannot be executed. I checked the problem on the console, console is not supported.
The IE browser in XP does not support console commands.
The console command is a console command used to debug JavaScript code. It usually uses the console. log () function instead of alert () to quickly obtain the content of a variable. Because IE in XP does not support console, subsequent Code cannot run.
The solution is to delete all the statements used for debugging. At this time, the default skin style can be displayed.
The IE browser in XP does not support certain cookie creation statements.
The reason for this is that I do not know which code is not well written. When I use the most basic alert (document. cookie) to return all cookie content, the returned value is null. When I use the cookie reading function to read a value, the returned value is undefined. Other browsers can return normally.
The strange thing is that when I use the IE developer toolbar for debugging, I can see that there is a cookie value under the current browser. At first, I thought there was a problem with reading the function from the cookie, because after all, the cookie content could not be read. Five different cookie reading functions are replaced before and after. Later I thought it was wrong, because alert (document. cookie) cannot return any content, and IE won't even support document. cookie ?! Is it because of the cookie generation function?
At this time, the customer gave an example website with similar features. I opened and tested the function normally. Since others are normal, it can certainly be achieved. I read its code and developed the js plug-in styleswitcher. JS used for skin replacement. Because the implementation steps are inconsistent with the existing website, I cannot use this plug-in for integration. I can only use it to generate cookies and read functions of cookies. The Code is as follows:
The Code is as follows: |
Copy code |
Function readCookie (name ){ Var nameEQ = name + "= "; Var ca = document. cookie. split (';'); For (var I = 0; I <ca. length; I ++ ){ Var c = ca [I]; While (c. charAt (0) = '') c = c. substring (1, c. length ); If (c. indexOf (nameEQ) = 0) return c. substring (nameEQ. length, c. length ); } Return false; } Function createCookie (name, value, days ){ If (days ){ Var date = new Date (); Date. setTime (date. getTime () + (days * 24x60*60*1000 )); Var expires = "; expires =" + date. toGMTString (); } Else expires = ""; Document. cookie = name + "=" + value + expires + "; path = /"; } |