cmp-cc / vue-cookies

A simple Vue.js plugin for handling browser cookies
MIT License
408 stars 70 forks source link

Cannot set session cookie in internet explorer 11 #29

Closed PaulVrugt closed 5 years ago

PaulVrugt commented 5 years ago

The cookie behavior is internet explorer is different from Chrome and Firefox. This causes a cookie that is set with "expires=0", to not be set at all, because internet explorer thinks the cookie has immediately expired. Chrome and firefox both treat "expires=0" as a session cookie.

cmp-cc commented 5 years ago

Set expires=0 is an error way,this is meaningless

current:

$cookies.set(keyName, value,0) // default expires=1d

$cookies.set(keyName, value,"0") // this is invalid
PaulVrugt commented 5 years ago

I don't get what you are trying to say. Your documentation states, that to set a session cookie, you need to use "0" (see the readme.md): this.$cookies.set("default_unit_second","input_value","0"); // end of session - use string!

this works for Chrome and Firefox, but not for IE. See also: https://stackoverflow.com/questions/25393331/internet-explorer-wont-let-me-create-session-cookie-using-this-javascript-funct

This fix makes sure it also works for IE. If you're saying "don't use "0" for expires for a session cookie, please change the readme.md, and explain how to properly set a session cookie using the component.

cmp-cc commented 5 years ago

Sorry, it was my fault. Thank you very much

PaulVrugt commented 5 years ago

Now I'm confused. You removed the text from the readme explaining how to set session cookies. So, how can we set session cookies using this component?

cmp-cc commented 5 years ago

use $cookies.remove(keyName [, path [, domain]]) method remove cookie

$cookies.set("default_unit_second","input_value","0") // Not in an elegant way

PaulVrugt commented 5 years ago

Sorry I still don't understand:

$cokies.remove this doesn't SET a session cookie, this removes a cookie

$cookies.set("default_unit_second","input_value","0") this is what we are using to set a session cookie, and it was also in in the documentation, but this doesn't work for Internet explorer, only for Chrome and Firefox.

Please explain to me how to implement the following scenario: I am using vue-cookies. I want to set a session cookie named "name" to a value "value". I need it to work in Internet explorer, firefox, and chrome. What is the exact code to use?

In my opinion, i should use: $cookies.set("default_unit_second","input_value","0") but for some reason you now removed this from the documentation, and it still doesn't work in internet explorer.

PaulVrugt commented 5 years ago

Just to be sure: A session cookie, is a cookie that only lives during the current browsing session, and is automatically removed by the browser when the current session ends. These cookies are widely used on the internet, and it would be very unlogical if this component doesn't support them.

cmp-cc commented 5 years ago

The browser will automatically clear the expired cookie

The effect is the same: remove a valid cookie $cookies.set("default_unit_second","input_value","0") and $cokies.remove

so, this should not be supported

cmp-cc commented 5 years ago

I'm sure, you're right now. I misunderstood what you meant.