简体   繁体   English

Chrome:刷新页面+ javascript重定向后未呈现背景图片

[英]Chrome: background-images not rendered after refreshing page + javascript redirect

I'm working on a website that loads pages through ajax. 我正在一个通过ajax加载页面的网站。 I keep track of the current location using the #!/url syntax. 我使用#!/ url语法跟踪当前位置。 If, when the page is firsty loaded, that page already has a url in the hash part of the url, I redirect to that page using javascript: 如果在页面首次加载时该页面在URL的哈希部分中已经有一个URL,则可以使用javascript重定向到该页面:

document.location = initialPage;

My content consists of a bunch of divs with position:absolute that are stacked in the correct order for display. 我的内容由一堆具有position:absolute的div组成,这些div以正确的顺序堆叠以进行显示。 My body background is a set of images that are periodically switched using jQuery slide. 我的身体背景是一组使用jQuery幻灯片定期切换的图像。 This works in all browsers, except (and here's the problem) in Chrome I sometimes lose the background images of my content divs. 这适用于所有浏览器,但(在Chrome中除外)(这是问题所在)有时我会丢失内容div的背景图片。 The most reliable way to reproduce is: 最可靠的复制方式是:

Notice that if you now refresh using Ctrl-F5 again, the page will look fine again. 请注意,如果现在再次使用Ctrl-F5刷新,页面将再次正常显示。 There is no significant javascript that runs on page load in either case. 在这两种情况下,页面加载都不会运行任何重要的javascript。 The background scroll is initialized, but the problem exists on pages without the backgrounds as well (the project pages). 初始化了背景滚动,但是问题也存在于没有背景的页面(项目页面)上。 I'm leaning towards this being a bug in Chrome, but I need this working. 我倾向于将其作为Chrome中的错误,但我需要此工作。 Can anyone suggest something? 有人可以建议吗?

Menno 门诺

Try to use absolute path for backgrounds on the CSS. 尝试在CSS上使用绝对路径作为背景。 Maybe it can help to determine the problem. 也许可以帮助确定问题。

Also you can try to apply backgrounds to blocks after page loading 您也可以尝试在页面加载后将背景应用于块

$(document).ready{
  $("#content").css("background","url(../Images/Css/bg_content.png)");
}

Also maybe this will be usefull. 同样也许这将是有用的。 When i request sample page like http://epsilon.tabeoka.be/fr/contacts . 当我请求示例页面如http://epsilon.tabeoka.be/fr/contacts时 Browser did 41-42 requests and uploads all images. 浏览器执行了41-42个请求,并上传了所有图像。 When i make it your way (with Ctrl-F5 pressed) - browser done only 31-33 request. 当我按自己的方式操作时(按住Ctrl-F5键)-浏览器仅完成了31-33个请求。 He dont upload the images for backgrounds. 他不上传图像作为背景。 Looks like he think that they allready uploaded. 看起来他认为他们已经上传了。

So when i disabled the cache on chrome - bug disappears. 因此,当我在Chrome上禁用缓存时,错误消失了。

Maybe you should try to add all background attributes into your page instead of CSS and also add to it random value like this: 也许您应该尝试将所有背景属性(而不是CSS)添加到您的页面中,并向其中添加随机值,如下所示:

<style>
  #content {
    background:url(../Images/Css/bg_content.png?rnd=123124);
  }
</style>

If it's really a Chrome bug (see my comment on your question), you can try replacing your background-image with an rgba background-color. 如果确实是Chrome错误(请参阅我对问题的评论),则可以尝试将背景图像替换为rgba背景色。 It's better and you can add a fallback for old browsers. 更好,您可以为旧版浏览器添加一个备用。

background-color: rgb(16,34,68);
background-color: rgba(16,34,68,.75);

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

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