0

Is there a way to open a web in my iframe and also make it auto scroll to it? In other words... I want to know how to combine this:

<a href="/example" target="myframe">

With this:

<a href="#myframe">

Thank you!

I dont want it to scroll within the iframe to an anoche within the target html. as a matter of fact the iframe doesnt have scrolling allowed. I want to scroll in the parent (root web) to the iframe

fpolloa
  • 99
  • 4
  • 13

2 Answers2

2

I found this solution. Works perfectly.

<a href="javascript:void(0)" onclick="IFrameScroll('http://www.asdf.com')">Class Name</a>


<script type="text/javascript">
    function IFrameScroll(link){
        window.myIframe.location=link;
        window.location.hash='myIframe'
    }
</script>
fpolloa
  • 99
  • 4
  • 13
1

Yes, you do that by putting the document fragment identifier (the thing starting with the # sign) after the URL, like this:

<a href="/example#myframe" target="myframe">

To have this work, your page (example in this case) must have a named anchor like this:

<a name="myframe">...
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • You're welcome. It this is indeed what you wanted, accept my answer by clicking the large check mark on its left. – Frank van Puffelen Nov 30 '12 at 20:15
  • Are you sure you have the necessary named anchor in the target HTML? I've updated my answer with such a fragment. – Frank van Puffelen Nov 30 '12 at 20:24
  • yes i am... Could it be the fact that this iframe is set to automatically adapt its height to its content? or any css property? – fpolloa Nov 30 '12 at 20:29
  • I dont want it to scroll within the iframe to an anoche within the target html. as a matter of fact the iframe doesnt have scrolling allowed. I want to scroll in the parent (root web) to the iframe – fpolloa Nov 30 '12 at 20:57
  • 1
    OK, that is a completely different problem then. Probably the easiest way to do this is to have a named anchor next to your iframe and (also) set that one with something like `window.location.href += 'myiframeanchor'`. Alternatively you can look into setting the location of the `scrollTop` property of the window, either directly in JavaScript or (likely easier) with `jQuery.scrollTo` (as discussed here: http://stackoverflow.com/questions/500336/how-to-scroll-to-an-element-in-jquery) – Frank van Puffelen Nov 30 '12 at 21:34