如何找出JavaScript中浏览器窗口跳转的原因? [英] How to Figure Out the Cause of a Browser Window Jump in JavaScript?

查看:66
本文介绍了如何找出JavaScript中浏览器窗口跳转的原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简化后,有一个html页面,其中嵌入了iframe,其中嵌入了传单地图:

simplified, have a html page in which an iframe is embedded in which a leaflet map is embedded:

<html>
...
  <iframe>
    ...
    <div class="leafletMap"></div>
    ...
  </iframe>
...
</html>

页面顶部的

是一个表单.在页面底部是iframe.该页面具有滚动条.如果我最初加载页面,则页面将滚动到顶部.如果由于用户与页面的交互而重新加载了iframe中的传单地图,则该页面会跳到浏览器窗口底部直至iframe.

on top of the page is a form. on the bottom of the page is the iframe. the page has a scroll bar. if i load the page intially the page is scrolled to the top. if due to user interaction with the page the leaflet map within the iframe is reloaded the page jumps down to the bottom of browser window to the iframe.

目的是重新加载传单地图后,浏览器窗口不会跳到底部.而是根本不跳.如果由于用户交互而使传单地图重新加载,则不应浏览器滚动.

aim is that the browser window does not jump to the bottom after a reload of the leaflet map. rather does not jump at all. if due to user interaction the leaflet map gets reloaded there should be no browser scrolling.

试图覆盖窗口,iframe和传单对象的焦点和/或滚动事件,但均未成功.如何找出导致页面跳动的原因或通常如何防止页面跳动?

tried to overwrite the focus and/or scroll events of the window, iframe and leaflet objects without success. how is it possible to figure out what causes the page jump or how to prevent it in general?

推荐答案

要禁用滚动位置,请在父页面上尝试以下操作:

To disable scroll position, on parent page try below:

<script>history.scrollRestoration = "manual"</script>

或者,父页面的onunload/beforeunload事件

window.beforeunload = function(){ window.scrollTo(0,0); }

这篇关于如何找出JavaScript中浏览器窗口跳转的原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆