Solutions for IE6, IE7, and IE8 that cannot read cookies properly

Source: Internet
Author: User

Cause analysis

It is normal to write the JavaScript code, the test has passed, in the IE10 IE7, 8, 9 rendering mode is also tested through. At this time, customer feedback in XP under the IE8 has a problem: the initial landing can not show the default skin, click to switch after refreshing can not show the skin after the switch.

Because it is through cookies to determine whether the default skin or the last user's choice of skin, so it is natural to think of the inability to read cookies. Start the VMware virtual machine, open the IE8 and IE Developer ToolBar tools for debugging, found that after the click of the cookie has been successfully created, but the code can not be executed, using the console to look at the problem, the original is not support console.

The console command is not supported for IE browsers under XP
The console command is a console command that is used to debug JavaScript code, usually using the Console.log () function instead of alert () to quickly get the contents of a variable. Because IE does not support console under XP, subsequent code cannot run.

The workaround is to delete all the debugging statements, and the default skin style can already be displayed.

XP's IE browser does not support certain statements that create cookies
This is because I do not know which code to write is not perfect. When I use the most basic alert (Document.cookie) to return all the cookie content, the return value is null, and the cookie read function reads a value and returns undefined. It can be returned normally in other browsers.

The strange thing is that when I use IE Developer Toolbar debugging, I can see the cookie value under the current browser. At first I thought it was a problem with the cookie reader function because the contents of the cookie were not read. 5 different cookie reader functions were changed before and after. Later, because the use of alert (Document.cookie) can not return any content, IE will not even document.cookie do not support it?! Is it because cookies generate functions?

At this time, the customer gave a similar function of the sample Web site, I opened the test to the normal function. Since other people's normal, certainly can achieve. I read the code, the skin-changing function using the Styleswitcher.js this JS plug-in to do. Because the implementation step does not match the existing Web site, I cannot use this plug-in integration, only its generate cookies, read cookies to use the function. 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.char at (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*24*60*60*1000));
    var expires = "; Expires= "+date.togmtstring ();
 }
  Else expires = "";
  Document.cookie = name+ "=" +value+expires+ "; path=/";
}

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.