How to make a target link to an iframe also scroll to it?

心已入冬 提交于 2019-12-11 17:27:14

问题


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


回答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">...



回答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>


来源:https://stackoverflow.com/questions/13652363/how-to-make-a-target-link-to-an-iframe-also-scroll-to-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!