ウィンドウの状態を保存する

書式

 WindowStore.init(cookieName, expired)

cookieName : 保存クッキー名(デフォルト:__window_store__)
expired : 期限

説明

 ウィンドウの状態を保存するにはWindowStore.init()を使います。存在するウィンドウの表示状態をクッキーに保存します。クッキーには{win01:false, win02:true}のようにハッシュ形式で保存されます。破棄したウィンドウは保存されず、表示または非表示になっているウィンドウが対象になります。

サンプルコード [実行]

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<link rel="stylesheet" href="default.css" type="text/css" media="all">
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="effects.js"></script>
<script type="text/javascript" src="window.js"></script>
<script type="text/javascript" src="window_ext.js"></script>
<script type="text/javascript"><!--
var win01, win02;
window.onload = function(){
win01 = new Window("win01", {
title: "ウィンドウ01", className: "dialog", top:100, left:60, zIndex: 100,
width:320, height:240, resizable: true, draggable:true });
win01.show();

win02 = new Window("win02", {
title: "ウィンドウ02", className: "dialog", top:150, left:120, zIndex: 101,
width:320, height:240, resizable: true, draggable:true });
win02.show();
}

function saveWindowData(){
WindowStore.init("__window_store__", new Date("2007/12/6"));
}

function checkCookie(){
alert(getCookie("__window_store__"));
}
// クッキー読み出し
function getCookie(theName__)
{
theName__ += "=";
theCookie__ = document.cookie+";";
start__ = theCookie__.indexOf(theName__);
if (start__ != -1)
{
end__ = theCookie__.indexOf(";",start__);
return unescape(theCookie__.substring(start__+theName__.length,end__));
}
return false;
}
// --></script>
</head>
<body>
<h1>ウィンドウの状態を保存する</h1>
<form>
<input type="button" value="保存する" onClick="saveWindowData()">
<input type="button" value="クッキーを表示" onClick="checkCookie()">
</form>
</body>
</html>