Any Way That I Can Assign Window.open(url) Into Cookies Array In Javascript?
Does anyone know how can I assign window.open(url) into cookies array in javascript? Below is the code that I used at the moment, but seem not really working well for me.... var e
Solution 1:
document.cookie === String
window.open === Object
Object !== String
therefore
document.cookie !== window.open
Solution 2:
It would be better to assign the uri string into the cookie array of the window you want to open then pull it out of the cookie when you want to call window.open. Inserting code or sensitive data into a cookie isn't good practice or secure.
Functions taken from: http://www.quirksmode.org/js/cookies.html
functioncreateCookie(name,value,days) {
if (days) {
var date = newDate();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
elsevar expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
functionreadCookie(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);
}
returnnull;
}
functioneraseCookie(name) {
createCookie(name,"",-1);
}
Then you could go:
createCookie('openUri', uriToOpen);
var openUri = readCookie('openUri');
if (openUri) {
window.open(openUri, 'myWindow');
}
Or something like that.
Hope this helps.
Post a Comment for "Any Way That I Can Assign Window.open(url) Into Cookies Array In Javascript?"