跳页到iframe中的ID



我有一个网页(http://www.willenhallprimary.org/science.shtml),其中包含一个iframe。IFRAME包含一个<h2 id="staff">Teachers</h2>标签,我想跳到使用父级URL和HASH,例如。http://www.willenhallprimary.org/science.shtml#staff。我也想等到页面加载后跳跃之前。(我可以使用?而不是#如果更容易。)

使用onload:javaScript调整iframe的大小(因此看起来像一个连续page)效果很好,但我不知道这是否会影响它。

 function rfs(){
   _i=document.getElementById('ym')
   _i.height=150
   if(typeof _i.contentDocument!=='undefined'){
     _cdd=_i.contentDocument.documentElement
     _i.height=Math.max(_cdd.scrollHeight,_cdd.offsetHeight,_cdd.clientHeight)+25
   }
   else {
     _cdb=_i.contentWindow.document.body
     _i.height=Math.max(_cdb.scrollHeight,_cdb.offsetHeight,_cdb.clientHeight)+25
   }
 }

这可能吗?这听起来很简单,但是我花了几个小时,没有任何效果。(我不是这个专家。)是否有更好的方法?

任何帮助都非常感谢。

@mplungjan感谢您的重定向 - 立即解决了它。

我最终得到的代码是:

window.onload=function(){
  if(window.location.hash!=''){
    document.getElementById('iframe_id').contentWindow.location.hash=window.location.hash
  }
}

似乎可以正常工作。很高兴: - )

最新更新