Kar*_*inz 3 html javascript scroll
情况:
首先:使用id miframe的iframe,显示一个名为suchen的锚点,即
<div id="suchen"></div>.
Run Code Online (Sandbox Code Playgroud)
第二.父框架.
目标:在父框架内建立一个类似的链接
<a class="LINK0" title="" href="javascript:springen('suchen');">w/e</a>
Run Code Online (Sandbox Code Playgroud)
使在内容的iframe滚动到锚俗尘.我的方法.
function springen(anker) {
var childWindow = document.getElementById("miframe").contentWindow;
// this should emulate a click on the ptAnchor DIV's child A HREF.
//childWindow.document.getElementById(anker).firstChild.click();
//childWindow.document.getElementById(anker).scrollIntoView();
// alternatively, this will simply scroll the child window to the top-left corner
//childWindow.scrollTo(0,200);
}
Run Code Online (Sandbox Code Playgroud)
childWindow.scrollTo(0,200);到目前为止工作,滚动发生在200.但我需要滚动到非常锚,无论它在iframe中.想法?
通常你会使用像这样的链接<a href="#your_anchor_name_or_id">Go to the anchor</a>.如果您想使用JavaScript执行此操作,则可以更改值window.location.hash.以下代码应在框架内执行此操作:
document.getElementById("the_id_of_your_iframe").contentWindow.location.hash = "your_anchor_name_or_id";
Run Code Online (Sandbox Code Playgroud)
如果您不想更改哈希值,则MDN上有一个示例.您可以为iframe修改它.