Forum Moderators: open
I'm not sure why it fails to apply the pages loaded in the frames from the mplayer directory if the cookie is set for the entire domain. Any ideas?
<a href="#" onmousedown="document.cookie='theme=Classic Theme;path=/;time()+2592000;' document.cookie='theme=Matrix Theme;path=/mplayer;time()+2593000;'" onclick="setActiveStyleSheet('Classic Theme'); parent.border.location.reload(); parent.copyright.location.reload(); parent.mplayer.location.reload(); parentcontent.location.reload(); return true;">Classic</a>
<h6>_~_</h6>
<a href="#" onmousedown="document.cookie='theme=Matrix Theme;path=/;time()+2592000;'; document.cookie='theme=Matrix Theme;path=/mplayer;time()+2593000;'" onclick="setActiveStyleSheet('Matrix Theme'); parent.border.location.reload(); parent.copyright.location.reload(); parent.mplayer.location.reload(); parentcontent.location.reload(); return true;">Matrix</a><br />
<br />
<br />
<a href="#" onmousedown="document.cookie='theme=Classic Theme;time()+2592000;/;/;'">classic create cookie</a>
<br/>
<a href="#" onmousedown="document.cookie='theme=Matrix Theme;time()+2592000;/;/;'">matrix create cookie</a><a href="#" onclick="setActiveStyleSheet('Classic Theme'); parent.border.location.reload(); parent.copyright.location.reload(); parent.mplayer.location.reload(); parentcontent.location.reload(); return true;">Classic</a>
<h6> ~ </h6>
<a href="#" onclick="setActiveStyleSheet('Matrix Theme'); parent.border.location.reload(); parent.copyright.location.reload(); parent.mplayer.location.reload(); parentcontent.location.reload(); return true;">Matrix</a>
<br />
function setActiveStyleSheet(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style")!= -1 && a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}function getActiveStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style")!= -1 && a.getAttribute("title") &&!a.disabled) return a.getAttribute("title");
}
return null;
}function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style")!= -1
&& a.getAttribute("rel").indexOf("alt") == -1
&& a.getAttribute("title")
) return a.getAttribute("title");
}
return null;
}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=/";
}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 null;
}window.onload = function(e) {
var cookie = readCookie("theme");
var title = cookie? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
}window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie("theme", title, 365);
}var cookie = readCookie("theme");
var title = cookie? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
Whitespace, commas and semicolons are not allowed in cookie values, so you'll need to escape them:
theme=' + escape("Classic Theme") + ';path[...]
Use unescape() when you read the cookie.
The correct way to set the expiration date is by using the expires attribute, which takes a date in GMT format. Also, time() is not a javascript method.
So, maybe this will work better:
var expdate = new Date();
expdate = expdate.getTime() + 2592000;
document.cookie = 'theme=' + escape('Classic Theme') + ';path=/; expires=' + expdate.toGMTString();