逆順に回答。
> さらに、[Shift]+リンククリックや[Ctrl]-Nで新たなウィンドウが立ち上がった場合にも、全てのウィンドウのcount値をリセットさせる
無理。ActiveX のようなもので OS に問い合わせられるなら別だけど(以前、それでウィンドウ名を得ていたコードなら見たことはある)。
> 表示させているウィンドウ上で、1つでもイベントが発生した場合、全てのウィンドウのcount値をリセットさせること
一度でも window.open で開けば、Window オブジェクトを記憶させることはできる。以下では、window1.html の WindowCollection オブジェクトで情報管理している。
window1.html:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>TEST</title>
<script type="text/javascript">
var WindowCollection = [ self ];
WindowCollection.maxSeconds = 10;
WindowCollection.currentSeconds = WindowCollection.maxSeconds;
function setTimer () {
if (--WindowCollection.currentSeconds) {
status = WindowCollection.currentSeconds; // 現在秒確認
setTimeout (setTimer, 1000);
} else {
for (var i = WindowCollection.length; i--; ) {
WindowCollection[i].location.href = 'http://example.com/';
}
}
}
onload = setTimer;
</script>
<script type="text/javascript" src="autologout1.js"></script>
<p>
<a href="window2.html" onclick="return openWindow (this); ">window2</a>
<a href="window3.html" onclick="return openWindow (this); ">window3</a>
</p>
window2.html, window3.html:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>TEST</title>
<script type="text/javascript" src="autologout1.js"></script>
<p>
<a href="window2.html" onclick="return openWindow (this); ">window2</a>
<a href="window3.html" onclick="return openWindow (this); ">window3</a>
</p>
autologout1.js:// WindowCollection is declared in window1.html
function openWindow (uri) {
var w = open (uri);
w.WindowCollection = WindowCollection;
WindowCollection.push (w);
return false;
}
document.onkeydown = document.onmousedown = function () {
WindowCollection.currentSeconds = WindowCollection.maxSeconds;
};
onunload = function () {
for (var i = 0, I = WindowCollection.length; i < I; i++) {
if (self == WindowCollection[i]) break;
}
WindowCollection.splice (i, 1);
};
なお、この方法だと window1.html が閉じられた途端に破綻する(あと、別ウィンドウでリロードないしページ遷移が発生したときも)。各ウィンドウごとに秒数を持たせて同期をとっても良いが、どうするにせよ、ウィンドウを一括管理する機構をどこかに用意する必要がある(サーバと連携がとれるなら、それが最善)。
あと、たぶんエラーハンドリングがものすごく大変。何でこんな場面で別ウィンドウを許しちゃうの?