Force parent frame, from within iFrame to Scroll

Posted on 2008-10-23
Medium Priority
Last Modified: 2012-08-13
Is there a way - from a JS event in my iFrame, to force the Parent Frame to Scroll to the top?
Question by:tbaseflug
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 10

Expert Comment

ID: 22786943
Only if the contents of the iframe and the parent are on the same domain.  There are security restrictions enforced on iframes which in most cases prevent you from accessing the iframe from the parent and vice versa.

Here's a bit of a discussion on the subject with a similar question to yours.  Also a bit of a solution for you provided you're using the same domain for both: http://bytes.com/forum/thread150689.html

Expert Comment

ID: 22787088
DId you try parent.scroll(0,0)?
<iframe src="2.htm" height="200" width="300"></iframe>
index2.htm (iframe)
<a href="javascript:void(0)" onclick="parent.scroll(0,0)">click</a>

Open in new window


Author Comment

ID: 22787176
It will be cross-domain, but assuming that I can get access to the parents source code - is there any workaround from that perspecive?
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 10

Expert Comment

ID: 22787235
Unfortunately for you, no.  If you try to access one document from the other (via the iframe) javascript will throw errors and not do anything else.

Author Comment

ID: 22787288
Is there a way - from within the iFrame - to force the iFrame to scroll up to the top of the iFrame or jump up to something like an anchor
LVL 10

Accepted Solution

Bane83 earned 2000 total points
ID: 22787355
Yes, you can tell the iframe to scroll itself or the parent to scroll itself.

From within the iframe or the parent (whichever you wish to scroll):

document.body.scroll(0,0) (as nick_bal mentioned)
Personally, I use document.body.scrollTop = 0;

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…
Suggested Courses

762 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