Solved

Javascript refresh/reload while keeping viewing location of page

Posted on 2004-03-27
7
691 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTPS jquery doesn't work 9 61
HTML5 Get data in table rows 5 29
Decoding Special HTML Characters using Javascript? 2 27
DataTables + iCheck + pagination Issue 2 23
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

773 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