• <i id='ksrW4'><tr id='ksrW4'><dt id='ksrW4'><q id='ksrW4'><span id='ksrW4'><b id='ksrW4'><form id='ksrW4'><ins id='ksrW4'></ins><ul id='ksrW4'></ul><sub id='ksrW4'></sub></form><legend id='ksrW4'></legend><bdo id='ksrW4'><pre id='ksrW4'><center id='ksrW4'></center></pre></bdo></b><th id='ksrW4'></th></span></q></dt></tr></i><div id='ksrW4'><tfoot id='ksrW4'></tfoot><dl id='ksrW4'><fieldset id='ksrW4'></fieldset></dl></div>
      <bdo id='ksrW4'></bdo><ul id='ksrW4'></ul>

      1. <tfoot id='ksrW4'></tfoot>

        <small id='ksrW4'></small><noframes id='ksrW4'>

        <legend id='ksrW4'><style id='ksrW4'><dir id='ksrW4'><q id='ksrW4'></q></dir></style></legend>

        window.history.pushState 刷新浏览器

        时间:2023-09-25
        <tfoot id='4uoAW'></tfoot>
            <tbody id='4uoAW'></tbody>

          1. <small id='4uoAW'></small><noframes id='4uoAW'>

                <bdo id='4uoAW'></bdo><ul id='4uoAW'></ul>
              • <i id='4uoAW'><tr id='4uoAW'><dt id='4uoAW'><q id='4uoAW'><span id='4uoAW'><b id='4uoAW'><form id='4uoAW'><ins id='4uoAW'></ins><ul id='4uoAW'></ul><sub id='4uoAW'></sub></form><legend id='4uoAW'></legend><bdo id='4uoAW'><pre id='4uoAW'><center id='4uoAW'></center></pre></bdo></b><th id='4uoAW'></th></span></q></dt></tr></i><div id='4uoAW'><tfoot id='4uoAW'></tfoot><dl id='4uoAW'><fieldset id='4uoAW'></fieldset></dl></div>
              • <legend id='4uoAW'><style id='4uoAW'><dir id='4uoAW'><q id='4uoAW'></q></dir></style></legend>
                  本文介绍了window.history.pushState 刷新浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在编写一些 javascript 代码,并使用 window.History.pushState 加载新的 HTML 页面,而不是使用 href 标签.我的代码(工作正常)看起来像这样.

                  I am working on some javascript code, and using window.History.pushState to load new HTML pages, instead of using href tags. My code (which is working fine) looks like this.

                  window.History.pushState({urlPath:'/page1'},"",'/page1')
                  

                  奇怪的是,这个失败,即重新加载浏览器

                  strangely, this fails, ie reloads the browser

                  window.History.pushState({urlPath:'/page2.php'},"",'/page2.php')
                  

                  但是这个有效,内容更新了,浏览器没有刷新!(注意 URL 是绝对的而不是相对的)

                  But this works, content is updated, browser not refreshed ! (notice the URL is absolute and not relative)

                  window.History.pushState({urlPath:'www.domain.com/page2.php'},"",'www.domain.com/page2.php')
                  

                  window.History.pushState 的文档 表示第三个参数 URL 可以是绝对的也可以是相对的 -

                  The documentation for window.History.pushState says that the third parameter URL can be either absolute or relative -

                  URL — 新历史条目的 URL 由该参数给出.笔记浏览器不会在调用后尝试加载此 URLpushState(),但它可能会稍后尝试加载 URL,例如用户重新启动浏览器后.新的 URL 不需要绝对;如果是相对的,则相对于当前 URL 进行解析.新 URL 必须与当前 URL 同源;否则,pushState() 将抛出异常.该参数是可选的;如果它没有指定,它被设置为文档的当前 URL.

                  URL — The new history entry's URL is given by this parameter. Note that the browser won't attempt to load this URL after a call to pushState(), but it might attempt to load the URL later, for instance after the user restarts the browser. The new URL does not need to be absolute; if it's relative, it's resolved relative to the current URL. The new URL must be of the same origin as the current URL; otherwise, pushState() will throw an exception. This parameter is optional; if it isn't specified, it's set to the document's current URL.

                  绝对 URL 似乎有效,但相对 URL 似乎无效.为什么会发生这种情况?

                  Absolute URLs seem to be working but relative seem to be not. Why is this happening?

                  推荐答案

                  简短的回答是 history.pushState(不是 History.pushState,它会抛出异常,window 部分是可选的)永远不会做你的建议.

                  The short answer is that history.pushState (not History.pushState, which would throw an exception, the window part is optional) will never do what you suggest.

                  如果页面正在刷新,那么它是由您正在做的其他事情引起的(例如,在地址栏更改的情况下,您可能正在运行的代码会转到新位置).

                  If pages are refreshing, then it is caused by other things that you are doing (for example, you might have code running that goes to a new location in the case of the address bar changing).

                  history.pushState({urlPath:'/page2.php'},"",'/page2.php') 与最新版本的 Chrome、IE 完全一样和 Firefox 给我和我的同事.

                  history.pushState({urlPath:'/page2.php'},"",'/page2.php') works exactly like it is supposed to in the latest versions of Chrome, IE and Firefox for me and my colleagues.

                  事实上,你可以在函数中放入任何你喜欢的东西:history.pushState({}, '', '这么久,感谢所有的鱼.不是一个真正的文件').

                  In fact you can put whatever you like into the function: history.pushState({}, '', 'So long and thanks for all the fish.not a real file').

                  如果您发布更多代码(特别注意 history.pushState 附近和使用 document.location 的任何地方的代码),那么我们将不止很乐意帮助您找出此问题的确切原因.

                  If you post some more code (with special attention for code nearby the history.pushState and anywhere document.location is used), then we'll be more than happy to help you figure out where exactly this issue is coming from.

                  如果你发布更多代码,我会更新这个答案(我最喜欢你的问题):)

                  If you post more code, I'll update this answer (I have your question favourited) :).

                  这篇关于window.history.pushState 刷新浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Web 浏览器未将 PHP 代码作为 PHP 代码处理 下一篇:如何解析“必须是字符串的实例,字符串给定&

                  相关文章

                  最新文章

                    <small id='5uyJa'></small><noframes id='5uyJa'>

                    • <bdo id='5uyJa'></bdo><ul id='5uyJa'></ul>

                    <legend id='5uyJa'><style id='5uyJa'><dir id='5uyJa'><q id='5uyJa'></q></dir></style></legend><tfoot id='5uyJa'></tfoot>

                      <i id='5uyJa'><tr id='5uyJa'><dt id='5uyJa'><q id='5uyJa'><span id='5uyJa'><b id='5uyJa'><form id='5uyJa'><ins id='5uyJa'></ins><ul id='5uyJa'></ul><sub id='5uyJa'></sub></form><legend id='5uyJa'></legend><bdo id='5uyJa'><pre id='5uyJa'><center id='5uyJa'></center></pre></bdo></b><th id='5uyJa'></th></span></q></dt></tr></i><div id='5uyJa'><tfoot id='5uyJa'></tfoot><dl id='5uyJa'><fieldset id='5uyJa'></fieldset></dl></div>