0

我有一个包含 iframe的网页(http://www.WillenhallPrimary.org/Science.shtml )。iframe 包含一个<h2 id="staff">Teachers</h2>标签,我想使用父 URL 和哈希值跳转到该标签,例如http://www.WillenhallPrimary.org/Science.shtml#staff。我也想等到页面加载后再跳转。(如果这样更容易,我可以使用 ? 而不是 # 。)

iframe 使用 onLoad:javascript 调整大小(所以它看起来像一个连续的页面),效果很好,但我不知道这是否会影响它。

 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
   }
 }

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

非常感谢任何帮助。

4

1 回答 1

0

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

我最终得到的代码是:

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

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

于 2016-12-07T09:24:39.680 回答