Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
单击iframe时,页面跳转到顶部_Iframe - Fatal编程技术网

单击iframe时,页面跳转到顶部

单击iframe时,页面跳转到顶部,iframe,Iframe,当我嵌入此gdrive iframe时,单击iframe后,我的页面会跳到顶部: <iframe height="400px" frameborder="0" width="600px" src="https://docs.google.com/document/d/1u9NFjTPBd-9mucQUPvkqLP84iV6uaEcJNF5vQdHmYh8/edit?usp=sharing&rm=embedded"></iframe> JSFiddle: 问:

当我嵌入此gdrive iframe时,单击iframe后,我的页面会跳到顶部:

<iframe height="400px" frameborder="0" width="600px" src="https://docs.google.com/document/d/1u9NFjTPBd-9mucQUPvkqLP84iV6uaEcJNF5vQdHmYh8/edit?usp=sharing&rm=embedded"></iframe>

JSFiddle:

问:它为什么这样做?我如何防止它这样做


我试图
避免违约
,但没有任何运气。非常感谢您的帮助。

您可以使用javascript检查iframe是否为活动元素,如果它是活动的,则返回到它

if(document.activeElement.tagName==“IFRAME”){
document.activeElement.scrollIntoView()文件
}


请参阅此示例。

我不确定这是否有用。顺便说一下,您可以使用onload属性向下滚动页面: onload=“滚动(0,屏幕高度);”


根据我的调查,这不是由iframe本身引起的。这是由嵌入的google文档执行的javascript造成的。当谷歌文档的编辑区域接收到焦点时,就会发生这种情况。如果您访问菜单区域,则不会发生任何事情,除非将某些内容添加到编辑区域。我尝试用sandbox属性限制iframe,这种行为不再发生,但是当然你不能使用googledocs

很抱歉,没有建议的解决方案。

Mybe这可以帮助您看到以下内容:
<iframe height="400px" frameborder="0" width="600px" src="https://docs.google.com/document/d/1u9NFjTPBd-9mucQUPvkqLP84iV6uaEcJNF5vQdHmYh8/edit?usp=sharing&rm=embedded"  onload="scroll(0,screen.height);"></iframe>