简体   繁体   English

在iframe上禁用滚动顶部事件

[英]Disable scroll top event on iframe

I have an iframe in my main page. 我的主页上有一个iframe。 The iframe generates images and sends it to the parent page. iframe会生成图像并将其发送到父页面。 My problem is that after iframe generates images my parent page scroll back to the top. 我的问题是iframe生成图像后,我的父页面会滚动回到顶部。 How can i disable scroll top event in iframe? 如何在iframe中禁用滚动顶部事件?

Fix : Setting the iframe to display none fix this issue but iframe in display none does not work for firefox. 修复:将iframe设置为不显示可解决此问题,但在不显示任何内容的iframe中,不适用于Firefox。 The iframe does not get loaded if it's set to display none so instead of I've used visibility : hidden. 如果将iframe设置为不显示,则不会加载该iframe,因此,与其使用可见性,不如隐藏。 But using visibility hidden I encounter the problem above. 但是使用隐藏的可见性我遇到了上面的问题。

Sample code 样例代码

<iframe id="image_source" src="http://local.testImages.com" width="100%" height="0px" style="visibility :hidden"></iframe>

This iframe is located on top of the page. 该iframe位于页面顶部。 Everytime it gets updated my main page scrolls back to top which the iframe is located. 每次更新时,我的主页都会滚动回到iframe所在的顶部。

How can i disable the main page from scrolling to top? 如何禁用主页滚动到顶部? or disable scroll event? 或禁用滚动事件?

Thanks, 谢谢,

这段代码通常会解决它,但是确实会导致一些滚动到快速的故障

oldscrole=window.scrollY;setInterval("if(window.scrollY==0&&window.scrollY+500<oldscrole){window.scroll(window.scrollY,oldscrole)}oldscrole=window.scrollY",1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM