#PAGETOP
アンカーの使用は、ウィンドウを一番上にスクロールすることです。代わりに、ウィンドウを0,0座標にスクロールする関数を書くことができます。
function ScrollToTop() {
window.scroll(0, 0);
}
この関数をIFrameに配置し、それを親ウィンドウから呼び出します。あなたのIFRAMEが親と子フレーム間のスクリプトを許可するようにブラウザのために、同じドメイン上にある必要があり
<a id="scrollToTop">Expand</a>
<script type="text/javascript">
document.getElementById("scrollToTop").onclick = function(e) {
var childWindow = document.getElementById("theIFrame").contentWindow;
// this should emulate a click on the ptAnchor DIV's child A HREF.
childWindow.document.getElementById("ptAnchor").firstChild.click();
// alternatively, this will simply scroll the child window to the top-left corner
childWindow.scrollTo(0,0);
}
</script>
<iframe id="theIFrame" src="someDocOnTheSameDomain.html"></iframe>
:親ドキュメントで
<iframe name="foo"></iframe>
<button>Expand</button>
<script type="text/javascript">
$(function(){
$('button').click(function(){
window.frames['foo'].location.hash = "top";
});
});
</script>
こんにちはKirtan、残念ながら、これは動作していないようでした。私はこれをprogrmaticallyでやっていくことに感謝します - ありがとう。 – tonyf
このような修正を行うには、iframeのsrcに同じドメインが必要です。 http://en.wikipedia.org/wiki/Same_origin_policyを参照してください。 –