简体   繁体   English

为什么在IE上,当我在页面重新加载之前将其添加到dom时,我的覆盖图没有显示?

[英]why on IE my overlay is not showed when i add it to the dom before a page reload?

On ie if i do something like this: 在ie,如果我做这样的事情:

var aOverlay = $('<div>');
aOverlay.addClass("modal_overlay");    
aOverlay.prependTo(aAppendTo);
window.location.reload(false);

then the overlay is not show at all. 那么叠加层根本不会显示。 but if i replace 但是如果我更换

window.location.reload(false);`

with

setTimeout(function(){window.location.reload(false);},300)

then it works. 然后就可以了。 Why ? 为什么呢

It is a browser-specific quirk if changes before the reload get displayed or not. 是否显示重新加载之前的更改,这是特定于浏览器的问题。 IE is trying to optimize page rendering by delaying page updates until all page updating has stopped. IE试图通过延迟页面更新直到所有页面更新都停止来优化页面呈现。

Q: If the page is about to be discarded, should recent page updates be rendered? 问:如果要丢弃该页面,是否应该呈现最近的页面更新?

A1: No! A1:不! A new page is coming, so simply display that. 即将出现一个新页面,因此只需显示它即可。 (IE) (IE)

A2: Yes! A2:是的! The updates are what the user is going to be staring at while the new page is fetched from the server. 从服务器获取新页面时,用户将盯着更新。 (Chrome, Firefox, Opera, Safari) (Chrome,Firefox,Opera,Safari)

The solution, as you found with setTimeout(...,300) , is to delay for a short interval before reloading the page. 正如使用setTimeout(...,300)发现的,解决方案是在重新加载页面之前延迟一小段时间。 This forces page updates to be rendered, so that they can be visible during the delay interval. 这将强制呈现页面更新,以便它们在延迟间隔内可见。

The delay can be shorter than 300ms. 延迟可以短于300ms。 In fact, it can be 0 or omitted entirely. 实际上,它可以为0或完全省略。 According to W3C standards, the interval is actually a minimum of 4ms. 根据W3C标准,间隔实际上至少为4ms。

This sample renders the overlay as a translucent gray layer over the entire page: 此示例将覆盖图呈现为整个页面上的半透明灰色层:

    <?php sleep(1); /* simulate typical server delay */ ?>
    <!DOCTYPE html><html><head>
    <style>
    .gray_overlay { position:fixed; top:0; left:0; height:100%; width:100%; 
       padding:0; margin: 0; z-index:999; background-color:#202020; opacity:0.4 }
    button { display:block; margin:20px }
    </style></head><body>
    <script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
    This is some text. Server takes 1s to respond.
    <button onclick="v1()">Version 1: Show overlay then reload instantly.</button>
    <button onclick="v2()">Version 2: Show overlay then reload in 0ms.</button>
    <script>
    var aAppendTo = $('body');
    var aOverlay = $('<div>');
    aOverlay.addClass("gray_overlay");    
    function v1() {
        aOverlay.prependTo(aAppendTo);
        window.location.reload();
    }
    function v2() {
        aOverlay.prependTo(aAppendTo);
        setTimeout(function(){window.location.reload();});
    }
    </script>
    </body></html>

在此处输入图片说明

暂无
暂无

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

相关问题 为什么我的页面在重新加载时会向下滚动一点 - why is my page scrolling down a bit when I reload it 为什么当我用 JavaScript DOM 更新 html 中的一个段落时,页面会重新加载? - Why when I update a paragraph in html with the JavaScript DOM does the page reload? 重新加载页面时,在脚本之前加载图像,可能会产生FOUC效果 - Load images before the scripts when I reload my page, possible FOUC effect jQuery和d3:为什么我在使用$(“ svg”)。remove()时重新加载页面? - jquery and d3: why does my page reload when I use $(“svg”).remove()? 为什么重新加载页面时我的更新 function 不执行? - Why doesn't my update function execute when I reload the page? 发送Ajax查询时,为什么我的页面试图重新加载? - Why my page trying to reload, when I am sending ajax query? 为什么当我添加以下引导程序时,我的页面会变成白色? - Why is that when I add in the following bootstrap my page become white? 为什么向下滚动时不重新加载数据,而在无限滚动中返回页面顶部时为什么不重新加载数据? - Why do not I reload the data when I scroll down and do it when I go back to the top of the page in my infinite scroll? 打开控制台时如何不重新加载页面? - How to not reload my page when I open up my console? 如何在不重新加载页面的情况下向我的 url 添加参数? - How can I add a parameter to my url, without reload the page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM