By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

window.opener.location.reload()

P: n/a
I have a page that opens a popup window and within the window, some databse
info is submitted and the window closes. It then refreshes the original
window using window.opener.location.reload(). The problem is that after the
reload, it brings you right to the top of the page. When I click 'refresh"
on the original page, it brings me back to the original viewing position.
Is there a way to duplicate this in from the popup window.

Also, is there a way to run window.opener.location.reload() when the popup
window is closed using the X in the upper right hand corner? Thanks!

Darren
Jul 23 '05 #1
Share this Question
Share on Google+
19 Replies


P: n/a
I haven't tried it between windows, but theoretically, you could capture
the document.body.scrollLeft and document.body.scrollTop (the one you
really need) values from the main window, reload and force those values
back to what they were before the reload.

So:

$pageoffset = document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;

For your second question, technically the window.onunload event should
give you the event handle you need. However, browser implementations and
aggressive settings to avoid popunders have rendered this event much
less reliable than it might have been in a utopian world where JS wasn't
abused for intrusive advertising.

-------------------------------------
J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com
-------------------------------------

Darren wrote:
I have a page that opens a popup window and within the window, some databse
info is submitted and the window closes. It then refreshes the original
window using window.opener.location.reload(). The problem is that after the
reload, it brings you right to the top of the page. When I click 'refresh"
on the original page, it brings me back to the original viewing position.
Is there a way to duplicate this in from the popup window.

Also, is there a way to run window.opener.location.reload() when the popup
window is closed using the X in the upper right hand corner? Thanks!

Darren

Jul 23 '05 #2

P: n/a
Thanks for the reply. Unfortunately I am fairley new to javascript. Could
you expand on your answer a little. Where exactly would I put this code?
Thanks!
"J Wynia" <jw****@speakeasy.net> wrote in message
news:BL********************@speakeasy.net...
I haven't tried it between windows, but theoretically, you could capture
the document.body.scrollLeft and document.body.scrollTop (the one you
really need) values from the main window, reload and force those values
back to what they were before the reload.

So:

$pageoffset = document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;

For your second question, technically the window.onunload event should
give you the event handle you need. However, browser implementations and
aggressive settings to avoid popunders have rendered this event much less
reliable than it might have been in a utopian world where JS wasn't abused
for intrusive advertising.

-------------------------------------
J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com
-------------------------------------

Darren wrote:
I have a page that opens a popup window and within the window, some
databse info is submitted and the window closes. It then refreshes the
original window using window.opener.location.reload(). The problem is
that after the reload, it brings you right to the top of the page. When
I click 'refresh" on the original page, it brings me back to the original
viewing position. Is there a way to duplicate this in from the popup
window.

Also, is there a way to run window.opener.location.reload() when the
popup window is closed using the X in the upper right hand corner?
Thanks!

Darren

Jul 23 '05 #3

P: n/a
First, put the code for your whole "close this window" process, which
will give you something like this:

function close_this_window(){
$pageoffset = document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;
window.close();
}

That function goes inside a script tag in your <head> tags.

Then, on your <body> tag, you'll attach your function to the "onunload"
event as well as to the "onclick" event of a button. For the body
instance of it, the last line of the function is useless, but lets you
use the same function for manual closing as well as accidental or
toolbar closing.

<body onunload="close_this_window();">

<button onclick="close_this_window();">Close Window</button>

This is all untested, so it may not work perfectly.

-------------------------------------
J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com
-------------------------------------

Darren wrote:
Thanks for the reply. Unfortunately I am fairley new to javascript. Could
you expand on your answer a little. Where exactly would I put this code?
Thanks!
"J Wynia" <jw****@speakeasy.net> wrote in message
news:BL********************@speakeasy.net...
I haven't tried it between windows, but theoretically, you could capture
the document.body.scrollLeft and document.body.scrollTop (the one you
really need) values from the main window, reload and force those values
back to what they were before the reload.

So:

$pageoffset = document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;

For your second question, technically the window.onunload event should
give you the event handle you need. However, browser implementations and
aggressive settings to avoid popunders have rendered this event much less
reliable than it might have been in a utopian world where JS wasn't abused
for intrusive advertising.

-------------------------------------
J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com
-------------------------------------

Darren wrote:
I have a page that opens a popup window and within the window, some
databse info is submitted and the window closes. It then refreshes the
original window using window.opener.location.reload(). The problem is
that after the reload, it brings you right to the top of the page. When
I click 'refresh" on the original page, it brings me back to the original
viewing position. Is there a way to duplicate this in from the popup
window.

Also, is there a way to run window.opener.location.reload() when the
popup window is closed using the X in the upper right hand corner?
Thanks!

Darren


Jul 23 '05 #4

P: n/a
I put all this code in the popup window. Everything works except for the
scroll position. Do I need to pass the scroll position from the parent
window to the popup somehow?

"J Wynia" <jw****@speakeasy.net> wrote in message
news:ws********************@speakeasy.net...
First, put the code for your whole "close this window" process, which will
give you something like this:

function close_this_window(){
$pageoffset = document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;
window.close();
}

That function goes inside a script tag in your <head> tags.

Then, on your <body> tag, you'll attach your function to the "onunload"
event as well as to the "onclick" event of a button. For the body instance
of it, the last line of the function is useless, but lets you use the same
function for manual closing as well as accidental or toolbar closing.

<body onunload="close_this_window();">

<button onclick="close_this_window();">Close Window</button>

This is all untested, so it may not work perfectly.

-------------------------------------
J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com
-------------------------------------

Darren wrote:
Thanks for the reply. Unfortunately I am fairley new to javascript.
Could you expand on your answer a little. Where exactly would I put this
code? Thanks!
"J Wynia" <jw****@speakeasy.net> wrote in message
news:BL********************@speakeasy.net...
I haven't tried it between windows, but theoretically, you could capture
the document.body.scrollLeft and document.body.scrollTop (the one you
really need) values from the main window, reload and force those values
back to what they were before the reload.

So:

$pageoffset = document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;

For your second question, technically the window.onunload event should
give you the event handle you need. However, browser implementations and
aggressive settings to avoid popunders have rendered this event much less
reliable than it might have been in a utopian world where JS wasn't
abused for intrusive advertising.

-------------------------------------
J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com
-------------------------------------

Darren wrote:

I have a page that opens a popup window and within the window, some
databse info is submitted and the window closes. It then refreshes the
original window using window.opener.location.reload(). The problem is
that after the reload, it brings you right to the top of the page. When
I click 'refresh" on the original page, it brings me back to the
original viewing position. Is there a way to duplicate this in from the
popup window.

Also, is there a way to run window.opener.location.reload() when the
popup window is closed using the X in the upper right hand corner?
Thanks!

Darren



Jul 23 '05 #5

P: n/a
Since you said you're learning, I'll try to explain rather than just
give you the fix. If it still doesn't make sense, reply and I'll give
you the fixed line.

There was a bug in the function. If you look at the first line inside
the function, and compare the DOM address (the document.body... part) to
the DOM address in the 3rd line, you should see the problem.

The 3rd line is setting the opener document's scroll location. However,
the first one isn't getting the scroll location from the opener
document's scroll location. Rather it's getting it from the current
document, which in this case, is the popup.

So, nothing needs to be passed per-se. It's just that the popup is
fetching the scroll location from the wrong place (mostly because I
wasn't thinking about the 2 window portion when I typed up the line to
get the scrolling info.

Darren wrote:
I put all this code in the popup window. Everything works except for the
scroll position. Do I need to pass the scroll position from the parent
window to the popup somehow?

"J Wynia" <jw****@speakeasy.net> wrote in message
news:ws********************@speakeasy.net...
First, put the code for your whole "close this window" process, which will
give you something like this:

function close_this_window(){
$pageoffset = document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;
window.close();
}

That function goes inside a script tag in your <head> tags.

Then, on your <body> tag, you'll attach your function to the "onunload"
event as well as to the "onclick" event of a button. For the body instance
of it, the last line of the function is useless, but lets you use the same
function for manual closing as well as accidental or toolbar closing.

<body onunload="close_this_window();">

<button onclick="close_this_window();">Close Window</button>

This is all untested, so it may not work perfectly.

-------------------------------------
J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com
-------------------------------------

Darren wrote:
Thanks for the reply. Unfortunately I am fairley new to javascript.
Could you expand on your answer a little. Where exactly would I put this
code? Thanks!
"J Wynia" <jw****@speakeasy.net> wrote in message
news:BL********************@speakeasy.net...
I haven't tried it between windows, but theoretically, you could capture
the document.body.scrollLeft and document.body.scrollTop (the one you
really need) values from the main window, reload and force those values
back to what they were before the reload.

So:

$pageoffset = document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;

For your second question, technically the window.onunload event should
give you the event handle you need. However, browser implementations and
aggressive settings to avoid popunders have rendered this event much less
reliable than it might have been in a utopian world where JS wasn't
abused for intrusive advertising.

-------------------------------------
J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com
-------------------------------------

Darren wrote:
>I have a page that opens a popup window and within the window, some
>databse info is submitted and the window closes. It then refreshes the
>original window using window.opener.location.reload(). The problem is
>that after the reload, it brings you right to the top of the page. When
>I click 'refresh" on the original page, it brings me back to the
>original viewing position. Is there a way to duplicate this in from the
>popup window.
>
>Also, is there a way to run window.opener.location.reload() when the
>popup window is closed using the X in the upper right hand corner?
>Thanks!
>
>Darren

Jul 23 '05 #6

P: n/a
Darren wrote:
I have a page that opens a popup window and within the window, some databse info is submitted and the window closes. It then refreshes the original window using window.opener.location.reload(). The problem is that after the reload, it brings you right to the top of the page. When I click 'refresh" on the original page, it brings me back to the original viewing position. Is there a way to duplicate this in from the popup window.

Also, is there a way to run window.opener.location.reload() when the popup window is closed using the X in the upper right hand corner? Thanks!

Darren


Here are three demo files that offer a possible solution.
Testing is up to you.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">

body {
font: 120% bold monospace;
}

</style>
<script type="text/javascript">

var subwin = null;
function open_subwin()
{
subwin = window.open(
'subwin.html',
'subwin',
'left=200,top=200,' +
'width=240,height=200,' +
'status,scrollbars,resizable'
);
if (subwin && !subwin.closed)
subwin.focus();
}

function saveYpos()
{
var y_scroll =
window.pageYOffset ?
pageYOffset :
document.documentElement
&& 'undefined' != typeof document.documentElement.scrollTop ?
document.documentElement.scrollTop :
document.body ?
document.body.scrollTop :
null;
if (y_scroll)
window.name = 'YSCROLL@' + y_scroll;
window.location.reload(true);
}

window.onload = function(m)
{
if (m = window.name.match(/YSCROLL@(\d+)/))
window.scrollTo(0, m[1] || 0);
window.name = '';
}

</script>
</head>
<body>
<form style="padding:1200px 0;">
-1<br>-2<br>-3<br>-4<br>-5<br>-6<br>-7<br>-8<br>-9<br><br>
<input
type="button"
value="add data"
onclick="open_subwin()">
</form>
</body>
</html>

[subwin.html]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">

body {
margin: 50px 10px;
}

</style>
<script type="text/javascript">

window.onunload = function()
{
if (opener
&& !opener.closed
&& opener.saveYpos)
{
opener.saveYpos();
}
}

</script>
</head>
<body>
<form
action="f_action.html"
method="post"
onsubmit="window.onunload=null">
<input
type="text"
name="newdata"
value="new data">
<input
type="submit"
value="done">
</form>
</body>
</html>

[f_action.html]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript">

if (opener
&& !opener.closed
&& opener.saveYpos)
{
opener.saveYpos();
}
self.close();

</script>
</head>
<body>
</body>
</html>

Jul 23 '05 #7

P: n/a
I changed the third line to window.opener.document.body.scrollTop =
$pageoffset;

and this still does not scroll back to the original position. Sorry for the
trouble!

Darren

"J Wynia" <jw****@speakeasy.net> wrote in message
news:Rf********************@speakeasy.net...
Since you said you're learning, I'll try to explain rather than just give
you the fix. If it still doesn't make sense, reply and I'll give you the
fixed line.

There was a bug in the function. If you look at the first line inside the
function, and compare the DOM address (the document.body... part) to the
DOM address in the 3rd line, you should see the problem.

The 3rd line is setting the opener document's scroll location. However,
the first one isn't getting the scroll location from the opener document's
scroll location. Rather it's getting it from the current document, which
in this case, is the popup.

So, nothing needs to be passed per-se. It's just that the popup is
fetching the scroll location from the wrong place (mostly because I wasn't
thinking about the 2 window portion when I typed up the line to get the
scrolling info.

Darren wrote:
I put all this code in the popup window. Everything works except for the
scroll position. Do I need to pass the scroll position from the parent
window to the popup somehow?

"J Wynia" <jw****@speakeasy.net> wrote in message
news:ws********************@speakeasy.net...
First, put the code for your whole "close this window" process, which
will give you something like this:

function close_this_window(){
$pageoffset = document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;
window.close();
}

That function goes inside a script tag in your <head> tags.

Then, on your <body> tag, you'll attach your function to the "onunload"
event as well as to the "onclick" event of a button. For the body
instance of it, the last line of the function is useless, but lets you
use the same function for manual closing as well as accidental or toolbar
closing.

<body onunload="close_this_window();">

<button onclick="close_this_window();">Close Window</button>

This is all untested, so it may not work perfectly.

-------------------------------------
J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com
-------------------------------------

Darren wrote:

Thanks for the reply. Unfortunately I am fairley new to javascript.
Could you expand on your answer a little. Where exactly would I put
this code? Thanks!
"J Wynia" <jw****@speakeasy.net> wrote in message
news:BL********************@speakeasy.net...
>I haven't tried it between windows, but theoretically, you could
>capture the document.body.scrollLeft and document.body.scrollTop (the
>one you really need) values from the main window, reload and force
>those values back to what they were before the reload.
>
>So:
>
>$pageoffset = document.body.scrollTop;
>window.opener.location.reload();
>window.opener.document.body.scrollTop = $pageoffset;
>
>For your second question, technically the window.onunload event should
>give you the event handle you need. However, browser implementations
>and aggressive settings to avoid popunders have rendered this event
>much less reliable than it might have been in a utopian world where JS
>wasn't abused for intrusive advertising.
>
>-------------------------------------
>J Wynia
>Myriad Intellect, Inc.
>"Web technology that earns its keep."
>www.myriadintellect.com
>-------------------------------------
>
>Darren wrote:
>
>
>>I have a page that opens a popup window and within the window, some
>>databse info is submitted and the window closes. It then refreshes
>>the original window using window.opener.location.reload(). The
>>problem is that after the reload, it brings you right to the top of
>>the page. When I click 'refresh" on the original page, it brings me
>>back to the original viewing position. Is there a way to duplicate
>>this in from the popup window.
>>
>>Also, is there a way to run window.opener.location.reload() when the
>>popup window is closed using the X in the upper right hand corner?
>>Thanks!
>>
>>Darren

Jul 23 '05 #8

P: n/a
You need to change the 1st line, not the 3rd. In general, you're trying
to ask the original page just how far down it's currently scrolled,
saving that number, doing your other stuff, and, when you close your
popup window reload the original page and move it back to where it was.
So, you need to make sure it's fetching the original location before
anything else will work.

Darren wrote:
I changed the third line to window.opener.document.body.scrollTop =
$pageoffset;

and this still does not scroll back to the original position. Sorry for the
trouble!

Darren

"J Wynia" <jw****@speakeasy.net> wrote in message
news:Rf********************@speakeasy.net...
Since you said you're learning, I'll try to explain rather than just give
you the fix. If it still doesn't make sense, reply and I'll give you the
fixed line.

There was a bug in the function. If you look at the first line inside the
function, and compare the DOM address (the document.body... part) to the
DOM address in the 3rd line, you should see the problem.

The 3rd line is setting the opener document's scroll location. However,
the first one isn't getting the scroll location from the opener document's
scroll location. Rather it's getting it from the current document, which
in this case, is the popup.

So, nothing needs to be passed per-se. It's just that the popup is
fetching the scroll location from the wrong place (mostly because I wasn't
thinking about the 2 window portion when I typed up the line to get the
scrolling info.

Darren wrote:
I put all this code in the popup window. Everything works except for the
scroll position. Do I need to pass the scroll position from the parent
window to the popup somehow?

"J Wynia" <jw****@speakeasy.net> wrote in message
news:ws********************@speakeasy.net...
First, put the code for your whole "close this window" process, which
will give you something like this:

function close_this_window(){
$pageoffset = document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;
window.close();
}

That function goes inside a script tag in your <head> tags.

Then, on your <body> tag, you'll attach your function to the "onunload"
event as well as to the "onclick" event of a button. For the body
instance of it, the last line of the function is useless, but lets you
use the same function for manual closing as well as accidental or toolbar
closing.

<body onunload="close_this_window();">

<button onclick="close_this_window();">Close Window</button>

This is all untested, so it may not work perfectly.

-------------------------------------
J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com
-------------------------------------

Darren wrote:
>Thanks for the reply. Unfortunately I am fairley new to javascript.
>Could you expand on your answer a little. Where exactly would I put
>this code? Thanks!
>
>
>"J Wynia" <jw****@speakeasy.net> wrote in message
>news:BL********************@speakeasy.net.. .
>
>
>
>>I haven't tried it between windows, but theoretically, you could
>>capture the document.body.scrollLeft and document.body.scrollTop (the
>>one you really need) values from the main window, reload and force
>>those values back to what they were before the reload.
>>
>>So:
>>
>>$pageoffset = document.body.scrollTop;
>>window.opener.location.reload();
>>window.opener.document.body.scrollTop = $pageoffset;
>>
>>For your second question, technically the window.onunload event should
>>give you the event handle you need. However, browser implementations
>>and aggressive settings to avoid popunders have rendered this event
>>much less reliable than it might have been in a utopian world where JS
>>wasn't abused for intrusive advertising.
>>
>>-------------------------------------
>>J Wynia
>>Myriad Intellect, Inc.
>>"Web technology that earns its keep."
>>www.myriadintellect.com
>>-------------------------------------
>>
>>Darren wrote:
>>
>>
>>
>>>I have a page that opens a popup window and within the window, some
>>>databse info is submitted and the window closes. It then refreshes
>>>the original window using window.opener.location.reload(). The
>>>problem is that after the reload, it brings you right to the top of
>>>the page. When I click 'refresh" on the original page, it brings me
>>>back to the original viewing position. Is there a way to duplicate
>>>this in from the popup window.
>>>
>>>Also, is there a way to run window.opener.location.reload() when the
>>>popup window is closed using the X in the upper right hand corner?
>>>Thanks!
>>>
>>>Darren
>
>


Jul 23 '05 #9

P: n/a
Darren wrote:
I changed the third line to window.opener.document.body.scrollTop =
$pageoffset;

and this still does not scroll back to the original position. Sorry for the trouble!

Darren


Read *all* responses, please!

If you're not going to, kindly make that clear up front
so people won't waste their time trying to help you...

Rob

Jul 23 '05 #10

P: n/a
I am sorry, I mis-spoke in my last post. My function looks like this:

function close_this_window(){
$pageoffset = window.opener.document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;
window.close();
}

This does not work for me!
"J Wynia" <jw****@speakeasy.net> wrote in message
news:vc********************@speakeasy.net...
You need to change the 1st line, not the 3rd. In general, you're trying to
ask the original page just how far down it's currently scrolled, saving
that number, doing your other stuff, and, when you close your popup window
reload the original page and move it back to where it was. So, you need to
make sure it's fetching the original location before anything else will
work.

Darren wrote:
I changed the third line to window.opener.document.body.scrollTop =
$pageoffset;

and this still does not scroll back to the original position. Sorry for
the trouble!

Darren

"J Wynia" <jw****@speakeasy.net> wrote in message
news:Rf********************@speakeasy.net...
Since you said you're learning, I'll try to explain rather than just give
you the fix. If it still doesn't make sense, reply and I'll give you the
fixed line.

There was a bug in the function. If you look at the first line inside the
function, and compare the DOM address (the document.body... part) to the
DOM address in the 3rd line, you should see the problem.

The 3rd line is setting the opener document's scroll location. However,
the first one isn't getting the scroll location from the opener
document's scroll location. Rather it's getting it from the current
document, which in this case, is the popup.

So, nothing needs to be passed per-se. It's just that the popup is
fetching the scroll location from the wrong place (mostly because I
wasn't thinking about the 2 window portion when I typed up the line to
get the scrolling info.

Darren wrote:

I put all this code in the popup window. Everything works except for
the scroll position. Do I need to pass the scroll position from the
parent window to the popup somehow?

"J Wynia" <jw****@speakeasy.net> wrote in message
news:ws********************@speakeasy.net...
>First, put the code for your whole "close this window" process, which
>will give you something like this:
>
>function close_this_window(){
>$pageoffset = document.body.scrollTop;
>window.opener.location.reload();
>window.opener.document.body.scrollTop = $pageoffset;
>window.close();
>}
>
>That function goes inside a script tag in your <head> tags.
>
>Then, on your <body> tag, you'll attach your function to the "onunload"
>event as well as to the "onclick" event of a button. For the body
>instance of it, the last line of the function is useless, but lets you
>use the same function for manual closing as well as accidental or
>toolbar closing.
>
><body onunload="close_this_window();">
>
><button onclick="close_this_window();">Close Window</button>
>
>This is all untested, so it may not work perfectly.
>
>-------------------------------------
>J Wynia
>Myriad Intellect, Inc.
>"Web technology that earns its keep."
>www.myriadintellect.com
>-------------------------------------
>
>Darren wrote:
>
>
>>Thanks for the reply. Unfortunately I am fairley new to javascript.
>>Could you expand on your answer a little. Where exactly would I put
>>this code? Thanks!
>>
>>
>>"J Wynia" <jw****@speakeasy.net> wrote in message
>>news:BL********************@speakeasy.net. ..
>>
>>
>>
>>>I haven't tried it between windows, but theoretically, you could
>>>capture the document.body.scrollLeft and document.body.scrollTop (the
>>>one you really need) values from the main window, reload and force
>>>those values back to what they were before the reload.
>>>
>>>So:
>>>
>>>$pageoffset = document.body.scrollTop;
>>>window.opener.location.reload();
>>>window.opener.document.body.scrollTop = $pageoffset;
>>>
>>>For your second question, technically the window.onunload event
>>>should give you the event handle you need. However, browser
>>>implementations and aggressive settings to avoid popunders have
>>>rendered this event much less reliable than it might have been in a
>>>utopian world where JS wasn't abused for intrusive advertising.
>>>
>>>-------------------------------------
>>>J Wynia
>>>Myriad Intellect, Inc.
>>>"Web technology that earns its keep."
>>>www.myriadintellect.com
>>>-------------------------------------
>>>
>>>Darren wrote:
>>>
>>>
>>>
>>>>I have a page that opens a popup window and within the window, some
>>>>databse info is submitted and the window closes. It then refreshes
>>>>the original window using window.opener.location.reload(). The
>>>>problem is that after the reload, it brings you right to the top of
>>>>the page. When I click 'refresh" on the original page, it brings me
>>>>back to the original viewing position. Is there a way to duplicate
>>>>this in from the popup window.
>>>>
>>>>Also, is there a way to run window.opener.location.reload() when the
>>>>popup window is closed using the X in the upper right hand corner?
>>>>Thanks!
>>>>
>>>>Darren
>>
>>


Jul 23 '05 #11

P: n/a
I did read your response, but can not get it to work either. You posted the
code for three pages, but I only see 2 filenames, so I could not tell which
code went with which filename. when the popup posts to the third page I get
an http verb error 405!

"RobB" <fe******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Darren wrote:
I have a page that opens a popup window and within the window, some

databse
info is submitted and the window closes. It then refreshes the

original
window using window.opener.location.reload(). The problem is that

after the
reload, it brings you right to the top of the page. When I click

'refresh"
on the original page, it brings me back to the original viewing

position.
Is there a way to duplicate this in from the popup window.

Also, is there a way to run window.opener.location.reload() when the

popup
window is closed using the X in the upper right hand corner? Thanks!

Darren


Here are three demo files that offer a possible solution.
Testing is up to you.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">

body {
font: 120% bold monospace;
}

</style>
<script type="text/javascript">

var subwin = null;
function open_subwin()
{
subwin = window.open(
'subwin.html',
'subwin',
'left=200,top=200,' +
'width=240,height=200,' +
'status,scrollbars,resizable'
);
if (subwin && !subwin.closed)
subwin.focus();
}

function saveYpos()
{
var y_scroll =
window.pageYOffset ?
pageYOffset :
document.documentElement
&& 'undefined' != typeof document.documentElement.scrollTop ?
document.documentElement.scrollTop :
document.body ?
document.body.scrollTop :
null;
if (y_scroll)
window.name = 'YSCROLL@' + y_scroll;
window.location.reload(true);
}

window.onload = function(m)
{
if (m = window.name.match(/YSCROLL@(\d+)/))
window.scrollTo(0, m[1] || 0);
window.name = '';
}

</script>
</head>
<body>
<form style="padding:1200px 0;">
-1<br>-2<br>-3<br>-4<br>-5<br>-6<br>-7<br>-8<br>-9<br><br>
<input
type="button"
value="add data"
onclick="open_subwin()">
</form>
</body>
</html>

[subwin.html]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">

body {
margin: 50px 10px;
}

</style>
<script type="text/javascript">

window.onunload = function()
{
if (opener
&& !opener.closed
&& opener.saveYpos)
{
opener.saveYpos();
}
}

</script>
</head>
<body>
<form
action="f_action.html"
method="post"
onsubmit="window.onunload=null">
<input
type="text"
name="newdata"
value="new data">
<input
type="submit"
value="done">
</form>
</body>
</html>

[f_action.html]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript">

if (opener
&& !opener.closed
&& opener.saveYpos)
{
opener.saveYpos();
}
self.close();

</script>
</head>
<body>
</body>
</html>

Jul 23 '05 #12

P: n/a
Darren wrote:
I did read your response, but can not get it to work either. You posted the code for three pages, but I only see 2 filenames [..]
That's because two of the files are referenced in two other files, and
one is the 'main' page. Just launch it.
so I could not tell which
code went with which filename. [..]
The one above it. I mean, seriously...
when the popup posts to the third page I get
an http verb error 405!


(snip)

Not up on verb errors. Just paste all three files into a local
directory, naming two with the name >above< them, and run the other.
Does it scroll?

Jul 23 '05 #13

P: n/a
Then you need to look elsewhere in your code, because in less than 2
minutes I whipped up 2 sample files and used the function you most
recently posted and it works fine. I just copied and pasted directly
from your most recent post and it works. I put this function in a test
file name parent.html along with a bunch of garbage and <br> tags above
it to ensure that I had to scroll to get to the link:

<a href="#" onclick="myWindow = window.open('popup.html', 'windowname',
'toolbar,width=150,height=100'); return false;">Function Test</a>

Then, I put your function into the header of another file called
popup.html, added some window.alert's to see exactly what's going on and
another link in that one like this:

<a href="#" onclick="close_this_window();return false;">Function Test</a>

I then opened parent.html, scrolled down to the link and clicked. The
new window popped up with the other link in it. I clicked that link and
got 3 popups with the appropriate values in them: 1184, 0, 1184. The
parent page moved up and back down as well as reloading.

In short, the code works.

Darren wrote:
I am sorry, I mis-spoke in my last post. My function looks like this:

function close_this_window(){
$pageoffset = window.opener.document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;
window.close();
}

This does not work for me!
"J Wynia" <jw****@speakeasy.net> wrote in message
news:vc********************@speakeasy.net...
You need to change the 1st line, not the 3rd. In general, you're trying to
ask the original page just how far down it's currently scrolled, saving
that number, doing your other stuff, and, when you close your popup window
reload the original page and move it back to where it was. So, you need to
make sure it's fetching the original location before anything else will
work.

Darren wrote:
I changed the third line to window.opener.document.body.scrollTop =
$pageoffset;

and this still does not scroll back to the original position. Sorry for
the trouble!

Darren

"J Wynia" <jw****@speakeasy.net> wrote in message
news:Rf********************@speakeasy.net...
Since you said you're learning, I'll try to explain rather than just give
you the fix. If it still doesn't make sense, reply and I'll give you the
fixed line.

There was a bug in the function. If you look at the first line inside the
function, and compare the DOM address (the document.body... part) to the
DOM address in the 3rd line, you should see the problem.

The 3rd line is setting the opener document's scroll location. However,
the first one isn't getting the scroll location from the opener
document's scroll location. Rather it's getting it from the current
document, which in this case, is the popup.

So, nothing needs to be passed per-se. It's just that the popup is
fetching the scroll location from the wrong place (mostly because I
wasn't thinking about the 2 window portion when I typed up the line to
get the scrolling info.

Darren wrote:
>I put all this code in the popup window. Everything works except for
>the scroll position. Do I need to pass the scroll position from the
>parent window to the popup somehow?
>
>"J Wynia" <jw****@speakeasy.net> wrote in message
>news:ws********************@speakeasy.net.. .
>
>
>
>>First, put the code for your whole "close this window" process, which
>>will give you something like this:
>>
>>function close_this_window(){
>>$pageoffset = document.body.scrollTop;
>>window.opener.location.reload();
>>window.opener.document.body.scrollTop = $pageoffset;
>>window.close();
>>}
>>
>>That function goes inside a script tag in your <head> tags.
>>
>>Then, on your <body> tag, you'll attach your function to the "onunload"
>>event as well as to the "onclick" event of a button. For the body
>>instance of it, the last line of the function is useless, but lets you
>>use the same function for manual closing as well as accidental or
>>toolbar closing.
>>
>><body onunload="close_this_window();">
>>
>><button onclick="close_this_window();">Close Window</button>
>>
>>This is all untested, so it may not work perfectly.
>>
>>-------------------------------------
>>J Wynia
>>Myriad Intellect, Inc.
>>"Web technology that earns its keep."
>>www.myriadintellect.com
>>-------------------------------------
>>
>>Darren wrote:
>>
>>
>>
>>>Thanks for the reply. Unfortunately I am fairley new to javascript.
>>>Could you expand on your answer a little. Where exactly would I put
>>>this code? Thanks!
>>>
>>>
>>>"J Wynia" <jw****@speakeasy.net> wrote in message
>>>news:BL********************@speakeasy.net.. .
>>>
>>>
>>>
>>>
>>>>I haven't tried it between windows, but theoretically, you could
>>>>capture the document.body.scrollLeft and document.body.scrollTop (the
>>>>one you really need) values from the main window, reload and force
>>>>those values back to what they were before the reload.
>>>>
>>>>So:
>>>>
>>>>$pageoffset = document.body.scrollTop;
>>>>window.opener.location.reload();
>>>>window.opener.document.body.scrollTop = $pageoffset;
>>>>
>>>>For your second question, technically the window.onunload event
>>>>should give you the event handle you need. However, browser
>>>>implementations and aggressive settings to avoid popunders have
>>>>rendered this event much less reliable than it might have been in a
>>>>utopian world where JS wasn't abused for intrusive advertising.
>>>>
>>>>-------------------------------------
>>>>J Wynia
>>>>Myriad Intellect, Inc.
>>>>"Web technology that earns its keep."
>>>>www.myriadintellect.com
>>>>-------------------------------------
>>>>
>>>>Darren wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>I have a page that opens a popup window and within the window, some
>>>>>databse info is submitted and the window closes. It then refreshes
>>>>>the original window using window.opener.location.reload(). The
>>>>>problem is that after the reload, it brings you right to the top of
>>>>>the page. When I click 'refresh" on the original page, it brings me
>>>>>back to the original viewing position. Is there a way to duplicate
>>>>>this in from the popup window.
>>>>>
>>>>>Also, is there a way to run window.opener.location.reload() when the
>>>>>popup window is closed using the X in the upper right hand corner?
>>>>>Thanks!
>>>>>
>>>>>Darren
>>>
>>>

Jul 23 '05 #14

P: n/a
JRS: In article <68***************************@LIGHTSHIP.NET>, dated
Wed, 4 May 2005 12:50:41, seen in news:comp.lang.javascript, Darren
<ne**@lan-specialist.com> posted :
Lines: 148
I am sorry, I mis-spoke in my last post. My function looks like this:

function close_this_window(){
$pageoffset = window.opener.document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;
window.close();
}

This does not work for me!
"J Wynia" <jw****@speakeasy.net> wrote in message
news:vc********************@speakeasy.net...
You need to change the 1st line, not the 3rd. In general, you're trying to
ask the original page


Note that when you top-post and overquote, regular experts are less
likely to bother to reply to your problem.

Likewise, they are less likely to bother to check J Wynia's replies.
Since he is of Myriad Intellect, he ought to be able to get things
right, even though he has no Organization:. As, indeed, should a lan-
specialist.

See Wednesday posting of newsgroup FAQ.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #15

P: n/a
Dr John Stockton wrote:
Likewise, they are less likely to bother to check J Wynia's replies.
Since he is of Myriad Intellect, he ought to be able to get things
right, even though he has no Organization:. As, indeed, should a lan-
specialist.


You might also note that "right" on this matter has always been a matter
of opinion (at least it was in 1995 when the RFC often cited was
issued). I've always been on the other side of the debate and have
always preferred TOFU (for text over, fullquote under) posting. However,
as those of us on this side of the question are both in the minority and
tend to be less evangelical in our beliefs about it, I will still defer
(more politely in most cases) and bottom post when other participants in
the discussion get worked up about it. Hopefully my deference in this
post has lowered your blood pressure.

Personally, I find it far more irritating when someone DOES try to trim
posts and, rather than cleaning up everything but the relevant material,
leaves random headers, line counts and server-generated article
identifiers in between, particularly when their signature espouses
"proper" trimming.

As for the Organization header. My participation in this entire thread
was routed through a machine that wasn't my primary workstation.
Figuring I'd kill some time and answer some questions in newsgroups, I
quickly tacked an nntp account onto the existing mail setup that was on
the machine. Hence, the Organization wasn't set, but the signature from
my mail account came across.

I'd also like to thank you for reminding me why I left Usenet behind
years ago. The medium being more important to participants than the
message was far too exhausting for the value the conversation that it
yielded.
Jul 23 '05 #16

P: n/a

"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in message
news:sZ**************@merlyn.demon.co.uk...
JRS: In article <68***************************@LIGHTSHIP.NET>, dated
Wed, 4 May 2005 12:50:41, seen in news:comp.lang.javascript, Darren
<ne**@lan-specialist.com> posted :
Lines: 148


I am sorry, I mis-spoke in my last post. My function looks like this:

function close_this_window(){
$pageoffset = window.opener.document.body.scrollTop;
window.opener.location.reload();
window.opener.document.body.scrollTop = $pageoffset;
window.close();
}

This does not work for me!
"J Wynia" <jw****@speakeasy.net> wrote in message
news:vc********************@speakeasy.net...
You need to change the 1st line, not the 3rd. In general, you're trying
to
ask the original page


Note that when you top-post and overquote, regular experts are less
likely to bother to reply to your problem.

Likewise, they are less likely to bother to check J Wynia's replies.
Since he is of Myriad Intellect, he ought to be able to get things
right, even though he has no Organization:. As, indeed, should a lan-
specialist.

See Wednesday posting of newsgroup FAQ.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME

Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet
Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of
News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail
News.


I am just wondering where I can find the newsgroup posting handbook? I use
Outlook Express and it automatically puts my mouse cursor at the top, so
that is where I start to type. I had no idea anyone would get their panties
in a bunch over it. Sorry!
Jul 23 '05 #17

P: n/a
Darren wrote:
"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in message:
(snip)
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.


I am just wondering where I can find the newsgroup posting handbook?

I use Outlook Express and it automatically puts my mouse cursor at the top, so that is where I start to type. I had no idea anyone would get their panties in a bunch over it. Sorry!


http://www.jibbering.com/faq/faq_notes/pots1.html

Jul 23 '05 #18

P: n/a
J Wynia wrote:
Dr John Stockton wrote:
> Likewise, they are less likely to bother to check J Wynia's replies.
> Since he is of Myriad Intellect, he ought to be able to get things
> right, even though he has no Organization:. As, indeed, should a lan-
> specialist.
You might also note that "right" on this matter has always been a matter
of opinion (at least it was in 1995 when the RFC often cited was
issued).


It is still a matter of opinion. But what you apparently ignore is that
there are opinions that can be justified by stable arguments and those that
are just that. Your opinion lacks the former and so belongs to the latter
which is why there is no Usenet guide that recommends (full) top-posting;
on the contrary, it is widely strongly recommended against it in favor of
well-trimmed quotes, not only in the FAQ of this newsgroup.

The argument is: top-posting is against the direction of understanding when
reading texts. This is not Jeopardy[tm] where the question follows the
answer. And full quotes serve no purpose, not even that of a reminder to
the reader which they should; it is in most cases completely unclear what
part of the quoted material one is referring to unless the whole(!) text
has been re-read. And there is exactly no advantage for the reader in
(full) top-posting; the only advantage is for the poster because he can
save time when posting. However, Usenet, as most media of electronic
discussion, is mainly a pull-medium, not a push-medium. Top-posting is a
thoughtless antisocial waste of bandwidth of all participants (including
the poster!) and the time of readers, guided by either under-/
misinformation or ignorance of the problem on the side of the poster.
I've always been on the other side of the debate
You are not debating, you are simply stating, since you have shown no
(and will be unable to show) stable arguments in favor of your opinion
that don't refer to *your* the advantage, i.e. to the advantage of the
perpetrator of top-posting.
[...] Hopefully my deference in this post has lowered your blood pressure.
This is not about blood pressure of someone, it is about simple courtesy
to everyone.
Personally, I find it far more irritating when someone DOES try to trim
posts and, rather than cleaning up everything but the relevant material,
leaves random headers, line counts and server-generated article
identifiers in between, particularly when their signature espouses
"proper" trimming.
It is better to have tried proper quoting and failed on some or all points
than not have tried at all. From making mistakes comes learning.
[...]
I'd also like to thank you for reminding me why I left Usenet behind
years ago.
If "you" don't like it here and are too stubborn to rethink "your"
standpoint, simply go away to a community that accepts your style (or try
to build one) instead of whining about the "bad bad Usenet" here. And if
"you" don't, "I" have to add "you" to "my" score or kill file to reduce
the noise, thus saving "me" bandwidth and time downloading and reading
messages. "I" doubt "you" really want that.
The medium being more important to participants than the message [...]


You did not understand. As a matter of fact, for a message to be properly
communicated, it is required that it is in a format that both the sender
and the recipient find at least acceptable, one they can agree on; this is
how the current widely used format evolved. If senders do not send what
recipients expect, their messages are simply unread, so they could as well
stop sending.
PointedEars
Jul 23 '05 #19

P: n/a
RobB wrote:
http://www.jibbering.com/faq/faq_notes/pots1.html


Thanks, I will look this over!
Jul 23 '05 #20

This discussion thread is closed

Replies have been disabled for this discussion.