私はテストサイトhere(まだ開発中です)を持っています。一度閉じると、一番上の小さな通知を隠そうとしています。Javascript Cookieを取得してDIVの状態を覚える方法はありますか?
<style type="text/css">
<!--
.hide {
display:none;
}
.show {
display:block;
}
-->
</style>
<script type="text/javascript">
<!--
var state;
window.onload=function() {
obj=document.getElementById('alert');
state=(state==null)?'show':state;
obj.className=state;
document.getElementById('close').onclick=function() {
obj.className=(obj.className=='show')?'hide':'show';
state=obj.className;
setCookie();
return false;
}
}
function setCookie() {
exp=new Date();
plusMonth=exp.getTime()+(31*24*60*60*1000);
exp.setTime(plusMonth);
document.cookie='State='+state+';expires='+exp.toGMTString();
}
function readCookie() {
if(document.cookie) {
state=document.cookie.split('State=')[1];
}
}
readCookie();
//-->
</script>
、その後:
現在、私のスクリプトは、このようなものです
<div id="alert" class="show" style="float: left; width: 100%;"><div style="width: 80%; text-align:left; float:left;">Sorry for the downtime, we were experiencing some problems with our web host. Everything should be back to normal now =D</div>
<div style="width: 18%; text-align:right; float:left; padding-right: 20px;"><a href='#' id="close">close</a></div> </div>
動作するようには思えません。何か案は?
ありがとうございます! :最初に返された配列のオフセットに保存されているので、代わりにこれを行うことになる
サム
完璧に動作します - ありがとうございます! –
@sm - erm、私の答えはあなたの問題を解決しましたか? – karim79
ああ、申し訳ありません - メイジさんが最初に答えたと思っていました。固定=) –