[英]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.