[英]jump page to id in an iframe
我有一個網頁( http://www.WillenhallPrimary.org/Science.shtml ),其中包含一個iframe。 iframe包含一個<h2 id="staff">Teachers</h2>
標簽,我想使用父URL和一個哈希值跳轉到該標簽,例如http://www.WillenhallPrimary.org/Science.shtml#staff 。 我還想等頁面加載后再跳轉。 (如果更容易,我可以使用?而不是#。)
使用onLoad:javascript調整了iframe的大小(因此它看起來像一個連續的頁面),效果很好,但我不知道這是否會影響它。
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
}
}
似乎還可以。 很高興 :-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.