Solved

Force parent frame, from within iFrame to Scroll

Posted on 2008-10-23
6
1,194 Views
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?
0
Comment
Question by:tbaseflug
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:Bane83
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
0
 
LVL 1

Expert Comment

by:nick_bal
ID: 22787088
DId you try parent.scroll(0,0)?
index1.htm

<p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p>

<p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p>

<p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p>
 

<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

0
 

Author Comment

by:tbaseflug
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?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 10

Expert Comment

by:Bane83
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.
0
 

Author Comment

by:tbaseflug
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
0
 
LVL 10

Accepted Solution

by:
Bane83 earned 500 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;
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now