Page action

D

DL

Hi,

I have a main page and a secondary page, what I'd like to do is like
this:
when the second page is opened and if the user take an action, that
is, click on a link on the second page, then, when the second page is
closed I want the main page to be refreshed
(so, for the second page, body onunload="opener.reload()")
but again, do so if only the user click on a link of the second page,
is there something like if conditionX is true
document.body.onunload=false?

Let me if the above problem statement is clear.

Thanks.
 
D

DL

Hi,

I have a main page and a secondary page, what I'd like to do is like
this:
when the second page is opened and if the user take an action, that
is, click on a link on the second page, then, when the second page is
closed I want the main page to be refreshed
(so, for the second page, body onunload="opener.reload()")
but again, do so if only the user click on a link of the second page,
is there something like if conditionX is true
document.body.onunload=false?

Let me if the above problem statement is clear.

Thanks.

Posted it too fast, so, there are some grammar errors etc. Here's
another way to describe it.

Page A -> Page B (pB)

Two possibilities for pB:
a) Click on a link
b) Do not click on anything and close pB

Desired outcome for pB
For the above a):
Make the body onunload="opener.reload()" valid for pB
For the above b):
Make the body onunload="opener.reload()" invalid for pB

How could we achieve it?

Thanks in advance.
 
S

SAM

Le 6/1/10 6:32 AM, DL a écrit :
Page A -> Page B (pB)

Two possibilities for pB:
a) Click on a link
b) Do not click on anything and close pB

Desired outcome for pB
For the above a):
Make the body onunload="opener.reload()" valid for pB
For the above b):
Make the body onunload="opener.reload()" invalid for pB

from B,
open mother (A)
opener.reload();
open grand mother (mother of A) and probably if A wasn't closed
opener.opener.reload()

but ... any way, to play with popups is bad ...
 
D

DL

Le 6/1/10 6:32 AM, DL a écrit :






from B,
open mother (A)
      opener.reload();
open grand mother (mother of A) and probably if A wasn't closed
      opener.opener.reload()

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.
 
S

SAM

Le 6/2/10 5:57 AM, DL a écrit :
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()"
 
D

DL

Le 6/2/10 5:57 AM, DL a écrit :
On Jun 1, 4:35 am, SAM <[email protected]>
wrote:
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()"

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
 
S

SAM

Le 6/2/10 5:07 PM, DL a écrit :
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>
 
D

DL

Le 6/2/10 5:07 PM, DL a écrit :
On Jun 2, 7:57 am, SAM <[email protected]>
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>
[/QUOTE]

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.
 
S

SAM

Le 6/3/10 5:57 AM, DL a écrit :
On Jun 2, 12:51 pm, SAM <[email protected]>
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>
 
S

SAM

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.
 
D

DL

Le 6/3/10 5:57 AM, DL a écrit :




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 thepageis reloaded.

function setTime() {
window.time = new Date();}

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

}

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

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

Yeah, I was totally mindless of forgetting the "function" key word...
just rewriting the page A code below...
but according to you, it looks like we're stuck, right? There must be
a solution to it!

Thanks, Sam. Don

Page A
======
<html>
<head>
</head>
<script type="text/javascript">
function whynot() {
document.getElementById('local').innerHTML = "local click test result:
Main page reloaded.";
}

function rl() {
if (reload()) {
document.getElementById('tell').innerHTML = "Main page reloaded.";
}

}
</script>

<body onload="rl();">

<h1>page A</h1>

<div id="local"></div>
<div id="tell"></div>

<form>
<input type="button" onclick="whynot()" value="local click test">
</form>

<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;
// F1.location = what.href;
F1.focus();
if(F1 || opener) {
opener.location.reload(); // reload the pA
opener.getElementById('tell').innerHTML = "Main page reloaded from
pB."; // indicate so
/* 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="pop();" onunload="if(F1 && !F1.closed) F1.close();">
<h1>page B</h1>

<form>
<input type="button" onclick="window.open('pageC.html?
id=762','','width=300,height=300')"

value="pC">
<!-- please note the above id value is dynamically generated by a
server side web scripting

language -->
</form>

</body>
</html>
 
D

DL

Le 6/3/10 5:57 AM, DL a écrit :
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 thepageis reloaded.
function setTime() {
window.time = new Date();}
function rl() {
var d = new Date();
if(!!window.time && d-window.time>0)
document.getElementById('tell').innerHTML = 'pagereloaded';

<body onunload="setTime();" onload="rl();">
No that can't work, the window forgets everything when a new (or same)pageis loaded in it.

Yeah, I was totally mindless of forgetting the "function" key word...
just rewriting the page A code below...
but according to you, it looks like we're stuck, right?  There must be
a solution to it!

Thanks, Sam.  Don

Page A
======
<html>
<head>
</head>
<script type="text/javascript">
 function whynot() {
document.getElementById('local').innerHTML = "local click test result:
Main page reloaded.";
  }

 function rl() {
        if (reload()) {
                document.getElementById('tell').innerHTML= "Main page reloaded.";
        }

   }
</script>

<body onload="rl();">

<h1>page A</h1>

<div id="local"></div>
<div id="tell"></div>

<form>
<input type="button" onclick="whynot()" value="local click test">
</form>

<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;
// F1.location = what.href;
F1.focus();
if(F1 || opener) {
        opener.location.reload(); // reload the pA
        opener.getElementById('tell').innerHTML = "Main page reloaded from
pB."; // indicate so
/* 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="pop();" onunload="if(F1 && !F1.closed) F1.close();">
<h1>page B</h1>

<form>
<input type="button" onclick="window.open('pageC.html?
id=762','','width=300,height=300')"

value="pC">
<!-- please note the above id value is dynamically generated by a
server side web scripting

language -->
</form>

</body>
</html>

Sam, here's an update. I've solved the problem, probably I can say
perfectly for Firefox but manage to have a workaround with IE.

Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top