Solved

Javascript refresh/reload while keeping viewing location of page

Posted on 2004-03-27
7
692 Views
Last Modified: 2011-04-14
I've got a child popup window which performs a duty and then closes itself after refreshing the parent / opener window. The parent window happens to be quite large, and when the page gets refreshed it automatically goes to the top of the page. I'd like it to stay where the user was last looking. (like how IE performs a refresh when clicking the button).

It seems like there would be a simple answer, but perhaps not. Maybe it needs to track where the user was last scrolled to and then envoke the scrollTo(); function. I'm not sure. I need help! Please let me know your thoughts. Here's the code I'm using currently. It's quite simple.

<script language="javascript">
          window.opener.location.reload();
          top.close();            
</script>


0
Comment
Question by:slinker
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10698495
Please provide the html/javascript of the child window.
0
 

Author Comment

by:slinker
ID: 10698678
I already have; That's pretty much the only important code in the child window. It refreshes the parent window, and closes itself.
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10698738
Oh, sorry. Here, try this code:

<script>
function refreshParent(){
var temp=window.opener.document.body.scrollTop;
window.opener.location.reload();
window.opener.scrollTo(0,temp);
self.close();
}
</script>
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 12

Accepted Solution

by:
lil_puffball earned 125 total points
ID: 10698748
Or, even better, this is cross browser:

<script language="javascript">
          window.opener.history.go();
          top.close();          
</script>
0
 

Author Comment

by:slinker
ID: 10698756
nope; didn't work. I tried alerting the temp variable to see what it was, and it did recieve a value (420), but the parent window didn't scroll down.
0
 

Author Comment

by:slinker
ID: 10698778
ahh, the second one worked great. That's interesting. It seems like that would pull the page from cache, but it's not... it's a dynamic page and its got the new info. Thanks a lot.
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10698784
Glad to help. Thanks for the points and the A! :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question