2016-12-06 76 views
0

我有一个网页(http://www.WillenhallPrimary.org/Science.shtml),它包含一个iframe。 iframe包含一个<h2 id="staff">Teachers</h2>标记,我想使用父网址和哈希例如http://www.WillenhallPrimary.org/Science.shtml#staff。我还想等到页面加载前跳跃。 (如果这更容易,我可以使用一个而不是#)。跳转页面到iframe中的id

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

这可能吗?这听起来很简单,但我花了几个小时看,没有任何工作。 (我不是这方面的专家。)有没有更好的方法来做到这一点?

任何帮助非常感谢。

+1

重复的http://stackoverflow.com/questions/13893256/jumping-to-anchor-in-iframe? – mplungjan

回答

0

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

我结束了的代码是:

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

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