Switch Content Script
Буду очень благодарен.
ЗЫ: у меня кукисы поставленные JS работают отменно, примерно в том же самом контексте
Именно так там и делается ;) но…
[HTML]<script type="text/javascript">
function switchcontent(id){
this.id = id;
this.show = true;
this.replaceTitle = false;
this.title = document.getElementById(this.id + '-title');
this.content = document.getElementById(this.id);
this.TitleShow = 'show';
this.TitleHide = 'hide';
this.setCookie = function(name, value, expires, path, domain, secure){
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
};
this.getCookie = function(name){
var cookie = " " + document.cookie;
var search = " " + name + "=";
var setStr = null;
var offset = 0;
var end = 0;
if (cookie.length > 0) {
offset = cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = cookie.indexOf(";", offset)
if (end == -1) end = cookie.length;
setStr = unescape(cookie.substring(offset, end));
}
}
return(setStr);
};
this.init = function(){
tself = this;
this.title.style.cursor = 'pointer';
var cook = this.getCookie(this.id);
if (cook=='null' && this.show == false) this.content.style.display = 'none'
if (cook=='hide') this.content.style.display = 'none'
if (this.replaceTitle == true && cook=='null' && this.show == true) this.title.innerHTML = this.TitleShow;
if (this.replaceTitle == true && cook=='null' && this.show == fasle) this.title.innerHTML = this.TitleHide;
if (this.replaceTitle == true && cook=='hide') this.title.innerHTML = this.TitleHide;
if (this.replaceTitle == true && cook=='show') this.title.innerHTML = this.TitleShow;
this.title.onclick = function(){
if (tself.content.style.display == 'none'){
tself.setCookie(tself.id, 'show');
tself.content.style.display = 'block';
if (tself.replaceTitle == true) tself.title.innerHTML = tself.TitleShow;
} else {
tself.content.style.display = 'none';
tself.setCookie(tself.id, 'hide');
if (tself.replaceTitle == true) tself.title.innerHTML = tself.TitleHide;
}
}
};
}
</script>
<div id="switchckick-title">click me</div>
<div id="switchckick">content</div>
<script language="javascript">
var swi = new switchcontent('switchckick');
swi.TitleShow = 'show';
swi.TitleHide = 'hide';
swi.replaceTitle = true;
swi.init();
</script>[/HTML]
Спасибо огромное за скрипт