[英]Scroll window to top of Iframe from iFrame with different domain than parent
內容 :
iframeResizer
插件-> iframe 沒有滾動條 (所有內容都顯示在父頁面上)-IFRAME始終根據其文檔高度調整大小 問題 :
如果用戶位於IFRAME的底部並執行操作,那么如何在IFRAME的頂部滾動用戶?
解決方案, 不工作:
window.scrollTo(0,0); // from iframe
來自iframe的帶有window.parent
所有內容(無法訪問)
在iframe主體頂部使用錨點並重寫window.location
有效的解決方案?
您可以嘗試使用document.body.scrollIntoView() 。
它應該可以在IE8 +和其他瀏覽器上運行(我僅在Chrome,FF和IE11中對其進行了測試)
document.body.scrollIntoView();
在Chrome&Mozilla(IE無法正常工作,為什么?)中,這可以很好地工作……但這似乎不是正確的方法。
演示 代碼筆演示
input
字段 input
來滾動父頁面 // IFRAME JS // initialize a "scroller" object var scrollPage = (function(){ var input = document.createElement("input"); input.style.position="absolute"; input.style.top="-50px"; document.body.insertBefore(input, document.body.firstChild); return function(){ input.focus(); }; })(); // use the "scroller" when needed scrollPage();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.