473,385 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

window.opener.location.reload()

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
19 30987
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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

"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
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
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
RobB wrote:
http://www.jibbering.com/faq/faq_notes/pots1.html


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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sentinel | last post by:
Hi all, I'm trying to reload a frame from a pop-up, but really cannot figure this out. Within my index.htm file, I make a link to call a pop-up frame with a javascript function that calls the...
1
by: Debbie Davis | last post by:
Hi there, I'm not very good at javascript but I'm using the following to close a child window and refresh a parent window after updating a database. It's within an ASP page. CODE <SCRIPT>...
2
by: Snolly | last post by:
Hi all, Here is my issue. I have a web page (lets call it page1) with an iframe in it that then opens a pop-up window (page2). The pop-up window is used to edit some data that was loaded into...
2
by: alex bazan | last post by:
I'm popping a window to a page with a different dns than the parent, and i want the opener's location reloaded when this window is closed. With Mozilla it seems that all the opener's methods and...
5
by: Hemanth | last post by:
Hello there, I'm running a script that opens a popup window (which is basically a form with checkboxes and a submit button). When I click the submit button I want to run a PHP script and target...
2
by: Raj | last post by:
Hi All, I have a problem with trying to refresh the parent window from child window in order to update data in the parent window. The sequence of events are 1) I click a button in the parent...
3
by: Dan M | last post by:
Is it possible to redirect or refresh the contents of Page1 from within Page2 where Page2 was opened by Page1?
1
by: JJ | last post by:
Hi All, How in ASP.NET, from PopUp window: 1) - save Data in Database; and after 2) a) - Reload the opener window b) -close PopYp window. Note:
7
by: Raffi | last post by:
I'm facing a tricky (at least for me) page reload/refresh scenario and need some help. I'm working on a web application which is primarily used with MSIE. The application has a main window with...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.