简体   繁体   English

奇怪的IE和Javascript问题

[英]Weird IE & Javascript issue

So I'm creating some HTML using javascript based on where the user clicks on the page. 因此,我根据用户在页面上单击的位置使用javascript创建了一些HTML。 On page load the script replaces an empty div with a ul and some data. 在页面加载时,脚本用ul和一些数据替换空的div。 The user clicks on that data to receive more and so on. 用户单击该数据可接收更多信息,依此类推。 Now when the user navigates off the page and then hits the back button to go back to the page, IE displays a blank page with the replaced divs, in all other browsers, FF, Opera, Safari, the page either reloads to the initial ul or goes back to the last state with the dynamic data in it. 现在,当用户导航离开页面,然后单击“后退”按钮返回页面时,IE在所有其他浏览器FF,Opera,Safari中显示带有替换div的空白页面,该页面会重新加载到初始ul或返回其中包含动态数据的最后一个状态。

Anyone have an idea as to what might be happening here? 有人对这里可能发生的事情有想法吗? Any help is appreciated. 任何帮助表示赞赏。

It sounds like you need to manage the history and state of your page. 听起来您需要管理页面的历史记录和状态。 Check our Brad Neuberg's Really Simple History . 检查我们的布拉德·诺伊伯格的《 真正简单的历史》

The behaviour of onload events when navigating backwards and forwards is not standard cross browser. 前后导航时onload事件的行为不是标准的跨浏览器。 As a general rule, I have found that when you click back, onload events tend not to work as the browser is loading it from cache rather than re-requesting the page. 通常,我发现当您单击返回时,onload事件往往不起作用,因为浏览器是从缓存中加载而不是重新请求页面。 What you can try is using the dom ready event rather than window load. 您可以尝试使用dom ready事件而不是窗口加载。

Trull's answer is along the right lines. Trull的答案是正确的。 Opera and later Firefox(>1.5) do not consider loading a page from the cache as requiring to trigger an onload event as the complete DOM state is also cached. Opera和更高版本的Firefox(> 1.5)不考虑从缓存加载页面,因为需要触发onload事件,因为还缓存了完整的DOM状态。

This is trivial to standardise across browsers, as Opera and Firefox do not exhibit this behaviour if you define a window.onunload event. 这对于跨浏览器进行标准化是微不足道的,因为如果您定义window.onunload事件,Opera和Firefox不会表现出此行为。 See http://developer.mozilla.org/en/Using_Firefox_1.5_caching 参见http://developer.mozilla.org/en/Using_Firefox_1.5_caching

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

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