简体   繁体   English

Ctrl + F5导致页面跳转,但F5不会

[英]Ctrl + F5 causes page to jump around but F5 does not

I am getting this strange behavior in Firefox browser in one of my client's website pages. 我在客户的一个网站页面上的Firefox浏览器中遇到这种奇怪的行为。

When I clear cache and refresh, or, refresh the page using Ctrl+F5 the page's formatting gets distorted. 当我清除缓存并刷新,或者使用Ctrl + F5刷新页面时,页面的格式会失真。

Immediately after this if I press F5 (and not Ctrl+F5) the page loads correctly. 此后,如果立即按F5(而不是Ctrl + F5),页面将正确加载。

I tried to troubleshoot and reset the browser as per the links here and here . 我尝试按照此处此处的链接进行故障排除并重置浏览器。

I also searched through the net and various forums of firefox but could not get this resolved. 我也搜索了网络和firefox的各种论坛,但无法解决此问题。

The Firefox version is 41 but I think the issue is with all the versions. Firefox版本是41,但我认为所有版本都存在问题。

This is working fine is Chrome. Chrome可以正常工作。

The URL with the issue is here . 问题所在的网址在这里

The following screenshot would also help understand my question. 以下屏幕截图也将有助于理解我的问题。

屏幕截图在这里

Please help! 请帮忙!

You have <div id="page"> whose width is set to 911px in CSS. 您有<div id="page">其宽度在CSS中设置为911px。 Then you have a script which changes its width to 100% on $(document).ready() event. 然后,您有了一个脚本,该脚本在$(document).ready()事件上将其宽度更改为100%。

Now, the ready event cannot fire until all synchronous JavaScript files, and the document itself is loaded. 现在,在所有同步JavaScript文件和文档本身都加载完毕之前,ready事件无法触发。 On a primed cache, the JavaScript files will load faster hence the ready event will fire quicker, setting the page width to 100% before you notice it. 在准备好的缓存中,JavaScript文件将加载得更快,因此ready事件将更快地触发,将页面宽度设置为100%,然后再注意。

However, on an empty cache, the JavaScript files will take longer time to load. 但是,在空的缓存上,JavaScript文件将需要更长的时间来加载。 The browser might render some part of the page before the ready event is fired. 在触发ready事件之前,浏览器可能会呈现页面的某些部分。 In fact, the second screenshot shows a "Transferring data from..." status which (most likely) means that the page is not loaded yet. 实际上,第二个屏幕截图显示了“正在从...传输数据”状态(很可能)意味着该页面尚未加载。

Solution: 解:

You want to prevent the page from jumping around when it is loaded and you need to set the page width via JavaScript and you cannot wait until document ready/page load. 您想防止页面在加载时跳动,并且需要通过JavaScript设置页面宽度,并且您不能等到文档就绪/页面加载后再进行页面设置。 One solution is to inline the JavaScript code that changes the page width. 一种解决方案是内联更改页面宽度的JavaScript代码。 First define these CSS classes: 首先定义以下CSS类:

#page { width: 911px; }
#fullwidth + #page { width: 100%; }

Then insert few lines of inline JavaScript: 然后插入几行嵌入式JavaScript:

<script>
if (mustBeFullWidth) {
    document.write('<div id="fullwidth"></div>');
}
</script>
<div id="page">
    <!-- content -->
</div>

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

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