Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1207
  • Last Modified:

Force parent frame, from within iFrame to Scroll

Is there a way - from a JS event in my iFrame, to force the Parent Frame to Scroll to the top?
0
tbaseflug
Asked:
tbaseflug
  • 3
  • 2
1 Solution
 
Bane83Commented:
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
 
nick_balCommented:
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
 
tbaseflugAuthor Commented:
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
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.

 
Bane83Commented:
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
 
tbaseflugAuthor Commented:
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
 
Bane83Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now