HTML frames: how to scroll to top of parent

Posted on 2013-10-21
Medium Priority
Last Modified: 2013-10-21
what JS code can i put in a child frame HTML  such that  upon entering that child page,
the parent scrolls to the top?
the child frame is very tall, and has a SUBMIT for a search.
(AJAX is not desirable for this situation)

perhaps some variation of:
document.body.scrollTop = document.documentElement.scrollTop = 0;
but reference the parent,
and do it by default upon entering the child page.

Question by:willsherwood
  • 2
  • 2
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39588174
Can you please post a link to your example page?  If you don't have one, then just create a simple example and upload so we can see what you are talking about.

Author Comment

ID: 39588198
the top level (parent) iframe =
<p><iframe style="background: transparent;" src="http://xxx.org/members/member-directory.php?k=1685" height="3085" width="700" seamless="seamless"></iframe></p>

(it's a protected directory, sorry)

in the file member-directory.php
i'd like a JS statement that scrolls the parent window to its top
LVL 54

Accepted Solution

Scott Fell,  EE MVE earned 2000 total points
ID: 39588266
You should simply recreate what you are doing with sample data in a non protected directory.  You want to recreate just a simple example.  This explains it pretty well http://css-tricks.com/reduced-test-cases/

If it helps, I created a sample page to be framed http://jsbin.com/iXOBePo/2/edit and the main page http://jsbin.com/ohUfOvA/2/edit?html,output

There is a button at the bottom.  Is that what you are trying to get to?  If not, please upload your own sample or edit the jsbin's.

Author Closing Comment

ID: 39589549
window.parent.$("body").animate({scrollTop:0}, 'slow');
did the trick

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

587 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