Home  >  Article  >  Web Front-end  >  Handling of IE8 browser cookies_javascript skills

Handling of IE8 browser cookies_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:56:121249browse

Handling of Cookies
I have encountered the problem of IE8 handling cookies before. I used IE8 to log in to a certain website. Once I logged in, I had to log in to switch pages before I could post. The problem is that IE8 does not accept the login cookie information. I read a lot of friends on the Internet who mentioned this problem. They all said that when logging into the forum, I have to log in repeatedly and IE8 cannot read the cookie. Haha, finally I carefully checked the relevant documents of IE8. Haha, it said that the security settings of IE8 have been improved and only cookies with clear domain name identification will be read.
Haha, it turns out to be my bad habit. I never explicitly set the domain name when using cookies:
cookie.set('skin', 'blue', 365, '') // The problem is here at the end' '
The domain name to send cookie information should be set here (cookie details [[url=]cookie in javascript[/url]]), but in the past, when IE did not set the domain name, it would be based on the page site visited. The domain name is the default domain name. But now IE8 doesn't work, just be honest and add the domain name. By the way, finally post the general cookie usage class:

Copy the code The code is as follows:

var Cookie = {
isAllowed: document.cookie && document.cookie != '',
set: function(cn, cv, d, dm){
var now = new Date();
var expire = new Date();
if (d == null || d == 0) {
d = 1;
}
expire.setTime(now.getTime() 3600000 * 24 * d);
document.cookie = cn '=' encodeURI(cv) ';expires=' expire.toGMTString() ';domain=' dm '; path=/';
},
clear: function(cn, dm){
if (this.get(name)) {
document.cookie = cn '=' ((domain) ? '; domain=' dm : '' ) '; expires=Thu, 01-Jan-70 00:00:01 GMT';
}
},
get: function(cn){
var dc = document.cookie;
var prefix = cn '=';
var begin = dc.indexOf('; ' prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) {
return null;
}
}
else {
begin = 2;
}
var end = document.cookie .indexOf(';', begin);
if (end == -1) {
end = dc.length;
}
return decodeURI(dc.substring(begin prefix.length, end));
}
};

Opacity/filter The use of transparent filter
Friends who know the lightbox effect know that it is because of a translucent mask The cover layer adds a lot of NB feeling to this effect. But in IE8, the support for transparent filters is not that good now. I even saw some foreign friends on Google saying that IE8 is going to refuse to set transparency for elements, except for supporting the transparency of pictures. Haha, I think when you open a similar program, the cool transparency effect in IE8 becomes a pain in your heart. But don’t worry, I am currently in beta2 and you can still use this effect. You just need to do this:
Copy the code The code is as follows:

function Opacity(element, value){
var style = element.style;
style.opacity = value / 100;
style.filter = "alpha(opacity= " value ")";
}

Just 3 lines of code, haha, there is no need to do browser sniffing like many JS libraries. I have tested it, IE6~8 (wrapped IE8 Standard view), Opera 9, NetScape8.1, FF2.x~3.x, and Google browsers are all well supported. Just pay attention to the order, be sure to use opacity first, and then use filter to ensure that it can be displayed normally. Nice and easy! Haha, that’s all for today!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn