window.location无法与window.location.href一起使用

window.location not working with window.location.href?

本文关键字:window location 一起 href      更新时间:2023-09-26

我有这个代码,

$('.editLayout #changeLayout').click(function() {
   $('html').height($(document).height());
   $('#fluidWrap').hide('scale');
   $.ajax({
       data: {
           mainLayout: true
       },
       success: function() {
          alert(window.location.href);
          window.location = window.location.href;
       }
   });
return false;
});

alert返回时,我得到一个带有哈希的有效url,例如

http://www.example.com/edit#_layout

但是页面不会刷新,如果我点击f5,尽管页面会正常刷新。

有什么想法吗?

尝试

window.location.reload(true);

更新(这里是铬的破解解决方案)

setTimeout(function(){window.location.reload(true);},100)

更新哈希不会重新加载页面,同样,将页面href设置为包含哈希的href也不会刷新页面。试试这个:

alert(window.location.href);
window.location = window.location.href.split('#')[0];

尝试

window.location.href = window.location.href;