Если открытие окна - это метод моего класса объектов.
В общем, я создал свой объект, определил у него метод, который открывает окно с определенной страницей. Тогда если закрыть это окно, то как программно узнать, закрыто ли оно? Как сюда включить свойство window.closed?
P.S. В этом методе новое окно я присвоил некой переменной.
KidsKilla
13.01.2006, 17:11
ты о жс?
делай проще:
window.open(src, "myName", blah-blah);
если окно закрыто, откроется новое. если окно открыто, в нём же откроется то что нужно.
Если очень интересно, то я могу привести исходный код моего скрипта. Надеюсь, станет понятно, почему нельзя использовать вышепредложенный метод.
Вот код:
function timers(id, left, top) {
this.timer1 = null;
this.timer2 = null;
this.id = id;
this.width = 200;
this.height = 200;
this.x = 0;
this.y = 0;
this.counter_pos = 30;
this.counter_neg = -30;
this.left = left;
this.top = top;
this.counter = 0;
this.radius = 100;
this.xbegin = 312;
this.ybegin = 152;
this.p = 100;
}
function openWin_virus(){
this.w = window.open('virus.html','win' + this.id,'resizable=no,height='+this.height+',width='+this.width);
this.w.moveTo(this.left, this.top);
}
timers.prototype.openWin_virus = openWin_virus;
function openWin_tree(){
this.w = window.open('tree.html', 'tree' ,'resizable=no,height='+this.height+',width='+this.width);
this.w.moveTo(412, 152);
}
timers.prototype.openWin_tree = openWin_tree;
function moveWin_up(){
var y = this.counter_neg;
this.w.moveBy(this.x, y);
if(this.w.screenTop <= 0){
if (this.timer2){
clearInterval(this.timer2);
this.timer2 = null;
}
eval(this.id + 'timer1') = setInterval(this.id + '.moveWin_down()', 1);
}
}
timers.prototype.moveWin_up = moveWin_up;
function moveWin_down(){
var y = this.counter_pos;
this.w.moveBy(this.x, y);
if(this.w.screenTop >= screen.availHeight - this.width){
if (this.timer1){
clearInterval(this.timer1);
this.timer1 = null;
}
eval(this.id + 'timer2') = setInterval(this.id + '.moveWin_up()', 1);
}
}
timers.prototype.moveWin_down = moveWin_down;
function moveWin_right(){
var x = this.counter_pos;
this.w.moveBy(x, this.y);
if(this.w.screenLeft >= 804){
if (this.timer1){
clearInterval(this.timer1);
this.timer1 = null;
}
eval(this.id + 'timer2') = setInterval(this.id + '.moveWin_left()', 1);
}
}
timers.prototype.moveWin_right = moveWin_right;
function moveWin_left(){
var x = this.counter_neg;
this.w.moveBy(x, this.y);
if(this.w.screenLeft <= 0){
if (this.timer2){
clearInterval(this.timer2);
this.timer2 = null;
}
eval(this.id + 'timer1') = setInterval(this.id + '.moveWin_right()', 1);
}
}
timers.prototype.moveWin_left = moveWin_left;
function moveRoundCircle(){
if(this.counter == this.p) this.counter = 0;
var rad = 2 * Math.PI * this.counter / this.p;
var x = this.xbegin + this.radius * (1 - Math.sin(rad));
var y = this.ybegin + this.radius * (1 - Math.cos(rad));
this.w.moveTo(x, y);
this.counter ++;
}
timers.prototype.moveRoundCircle = moveRoundCircle;
var t1, t2, t3, t4, t5;
function init(){
t1 = new timers('t1', 0, 0);
t1.openWin_virus();
t1.w.focus();
setTimeout("t1.timer1 = setInterval('t1.moveWin_down()', 1);", 11000);
t2 = new timers('t2', 824, 404);
t2.openWin_virus();
t2.w.focus();
setTimeout("t2.timer1 = setInterval('t2.moveWin_up()', 1);", 11000);
t3 = new timers('t3', 0, 504);
t3.openWin_virus();
t3.w.focus();
setTimeout("t3.timer1 = setInterval('t3.moveWin_right()', 1);", 11000);
t4 = new timers('t4', 824, 0);
t4.openWin_virus();
t4.w.focus();
setTimeout("t4.timer1 = setInterval('t4.moveWin_left()', 1);", 11000);
t5 = new timers('t5', 412, 252);
t5.openWin_tree();
t5.w.focus();
setTimeout("t5.timer1 = setInterval('t5.moveRoundCircle()', 1);", 10000);
}
Кстати, вот реализация этого скрипта:
http://www.zapill.narod.ru
KidsKilla
14.01.2006, 17:03
тогда можно что то типа:
self.onunld = function(){
alert("closed!");
}
var win = window.open("about:blank", "win", "");
win.document.write('<html><head><title>xxx</title></head><body onunload="if(window.opener) window.opener.onunld()"><a href="http://ya.ru">ya</a></body></html>')
Учим матчасть
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/closed.asp
в каких бровзерах это пашет, проверяй сам
Работает на vBulletin ® версия 3.7.3. Copyright ©2000-2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Copyright © 1999-2008 Flasher.ru. All rights reserved.