From: DL on
On Jun 2, 7:57 am, SAM <stephanemoriaux.NoAd...(a)wanadoo.fr.invalid>
wrote:
> Le 6/2/10 5:57 AM, DL a écrit :
>
> > On Jun 1, 4:35 am, SAM <stephanemoriaux.NoAd...(a)wanadoo.fr.invalid>
> > wrote:
>
> >> but ... any way, to play with popups is bad ...
>
> > Sorry, Sam, I don't get it.  But there's a good reason for doing what
> > I'm doing.
>
> Sorry, but my answer certainly didn't give the solution.
>
> Supposing links in B open called file in B.
> Then,
> - will B remember the "onunload" ? ?
> - will B remenber its opener ?
>
> Test and try something like that in files in B :
>
> var pB = false;
>
> function reloadMain() {
> if(!opener) alert('mother is lost !');
> else if(pB) opener.reload();}
>
> function yesNo() {
> pB = true;
> setTimeout(function(){pB=false;},100);}
>
> function init() {
> var a = document.links, n = a.length;
> while(n--) a[n].onclick = yesNo;
>
> }
>
> <body onload="init()" onunload="reloadMain()"
>
> --
> sm

Oh, sorry Sam, it's not href links on pB but window.open
so, we need to re-write the following line:
var a = document.links, n = a.length;

some sort of if (new window) {pB = true;}

?

Thanks.

Don
From: SAM on
Le 6/2/10 5:07 PM, DL a �crit :
> On Jun 2, 7:57 am, SAM <stephanemoriaux.NoAd...(a)wanadoo.fr.invalid>
> wrote:
>>
>> function init() {
>> var a = document.links, n = a.length;
>> while(n--) a[n].onclick = yesNo;
>> }
>>
>> <body onload="init()" onunload="reloadMain()"
>
> Oh, sorry Sam, it's not href links on pB but window.open

there too ? (not only in A ?)
So there is no problem in B if it launches a new window.
Just B on unload will have to close its daughter.

> so, we need to re-write the following line:
> var a = document.links, n = a.length;
>
> some sort of if (new window) {pB = true;}
>
> ?

Files in popup B :

[script]
var F1 = false;
function pop(what) {
if(!F1 || F1.closed)
F1 = window.open('','F1','width=300,height=300');
F1.location = what.href;
F1.focus();
if(opener) opener.location.reload(); /* refresh A */
return false;
}
function init() {
var a = document.links, n = a.length;
while(n--) a[n].onclick = function() { return pop(this); }
}

[html]
<body onload="init()" onunload="if(F1 && !F1.closed) F1.close();">
<h1>examples</h1>
<p><a href="http://google.com">google</a>
<a href="http://www.yahoo.com/">yaHoo!</a>
<a href="http://wikipedia.org/">Wiki Pedia</a>

--
sm
From: DL on
On Jun 2, 12:51 pm, SAM <stephanemoriaux.NoAd...(a)wanadoo.fr.invalid>
wrote:
> Le 6/2/10 5:07 PM, DL a écrit :
>
> > On Jun 2, 7:57 am, SAM <stephanemoriaux.NoAd...(a)wanadoo.fr.invalid>
> > wrote:
>
> >> function init() {
> >> var a = document.links, n = a.length;
> >> while(n--) a[n].onclick = yesNo;
> >> }
>
> >> <body onload="init()" onunload="reloadMain()"
>
> > Oh, sorry Sam, it's not href links on pB but window.open
>
> there too ? (not only in A ?)
> So there is no problem in B if it launches a new window.
> Just B on unload will have to close its daughter.
>
> > so, we need to re-write the following line:
> > var a = document.links, n = a.length;
>
> > some sort of if (new window) {pB = true;}
>
> > ?
>
> Files in popup B :
>
> [script]
> var F1 = false;
> function pop(what) {
> if(!F1 || F1.closed)
> F1 = window.open('','F1','width=300,height=300');
> F1.location = what.href;
> F1.focus();
> if(opener) opener.location.reload(); /* refresh A */
> return false;}
>
> function init() {
> var a = document.links, n = a.length;
> while(n--) a[n].onclick = function() { return pop(this); }
>
> }
>
> [html]
> <body onload="init()" onunload="if(F1 && !F1.closed) F1.close();">
> <h1>examples</h1>
> <p><a href="http://google.com">google</a>
>     <a href="http://www.yahoo.com/">yaHoo!</a>
>     <a href="http://wikipedia.org/">Wiki Pedia</a>
>
> --
> sm

The following line seems a "suspect", it closes page A, which isn't
intended:
if(F1 && !F1.closed) F1.close();
Goal is to reload page A only if page C is opened.

Here's my attempt per your code flow.

page A
======
<html>
<head>
</head>
<script type="text/javascript">
rl() {
if (self.reload()) {
document.getElementById('tell').innerHTML == "Main page reloaded.";
alert("has been reloaded");
}
}
</script>

<body onload="rl();">
<h1>page A</h1>
<div id="tell"></div>
<a href="pageB.html" target="_new">go to page B</a>
</body>
</html>

page B
======

<html>
<head>
<script type="text/javascript">
var F1 = false;
function pop(what) {
if(!F1 || F1.closed)
F1 = window.open('','F1','width=300,height=300');
F1.location = what.href;
F1.focus();
if(opener) opener.location.reload(); /* refresh A */
return false;
}

function init() {
var a = document.links, n = a.length;
while(n--) a[n].onclick = function() { return pop(this); }

}
</script>
</head>


<body onload="init()" onunload="if(F1 && !F1.closed) F1.close();">
<h1>page B</h1>
<form>
<input type="button"
onclick="window.open('pageC.html','','width=300,height=300')"
value="pC">
</form>
</body>
</html>


page C
======
<html>
<head>
</head>

<body>
<h1>page C</h1>
</body>
</html>


Thanks.
From: SAM on
Le 6/3/10 5:57 AM, DL a �crit :
> On Jun 2, 12:51 pm, SAM <stephanemoriaux.NoAd...(a)wanadoo.fr.invalid>
> wrote:

>> Files in popup B :
>>
>> [script]
[snip]

> The following line seems a "suspect", it closes page A, which isn't
> intended:
> if(F1 && !F1.closed) F1.close();

absolutely not !
that closes the C's window-popup
(when you leave or close the B window-popup)

> Goal is to reload page A only if page C is opened.

it is exackatelly what that does !
Can't you try given code ?

> Here's my attempt per your code flow.
>
> page B
> ======
>
> <html>
> <head>
> <script type="text/javascript">
> var F1 = false;
> function pop(what) {
> if(!F1 || F1.closed)
> F1 = window.open('','F1','width=300,height=300');

F1.location = what;
/*

> F1.location = what.href;

*/
> F1.focus();
> if(opener) opener.location.reload(); /* refresh A */
> return false;
> }

/* suppress that that is of no use if button

> function init() {
> var a = document.links, n = a.length;
> while(n--) a[n].onclick = function() { return pop(this); }
>
> }
*/

> </script>
> </head>
>
>
> <body onunload="if(F1 && !F1.closed) F1.close();">
> <h1>page B</h1>

<p><button onclick="pop('pageC.html')">p C</button>

> </body>
> </html>
>
>
> page C
> ======
> <html>
> <head>
> </head>
>
> <body>
> <h1>page C</h1>
> </body>
> </html>


--
sm
From: SAM on
Le 6/3/10 5:57 AM, DL a �crit :
>
> page A
> ======
> <html>
> <head>
> </head>
> <script type="text/javascript">
> rl() {
> if (self.reload()) {

where did you find that ?

maybe
if(self.location.reload)
but ... not better

function rl() {
document.getElementById('tell').innerHTML = new Date();
}

I don't think you can test if the page is reloaded.


function setTime() {
window.time = new Date();
}
function rl() {
var d = new Date();
if(!!window.time && d-window.time>0)
document.getElementById('tell').innerHTML = 'page reloaded';
}

<body onunload="setTime();" onload="rl();">

No that can't work, the window forgets everything when a new (or same)
page is loaded in it.

--
sm