location.hash in an iframe scrolls the parent window

Posted by Ben Clayton on Stack Overflow See other posts from Stack Overflow or by Ben Clayton
Published on 2010-06-18T10:42:31Z Indexed on 2010/06/18 10:53 UTC
Read the original article Hit count: 499

Filed under:
|
|

Hi all. I have a page with an iframe. Inside the iframe is code (that I can't change) that sets location.hash to the id of an element in the iframe window.

This has the unwanted effect of scrolling my outermost browser window so that the top of the window touches the top of the iframe. This is quite annoying as I have a toolbar above the iframe that is vital to my app.

Is there any way of preventing the setting of location.hash affecting the scroll position of the main window?

Will preventDefault help me out here?

Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html