简体   繁体   English

window.location.replace() 不起作用

[英]window.location.replace() is not working

just wanna ask why does window.location.replace is not working in my page.只是想问为什么 window.location.replace 在我的页面中不起作用。 I've been working on it for weeks.我已经为此工作了好几个星期。 It works fine on my other pages, although those pages have DevExpress components, but in this particular page where I am only using normal html and asp tags and components it is not working.它在我的其他页面上运行良好,虽然这些页面有 DevExpress 组件,但是在这个我只使用普通 html 和 asp 标签和组件的特定页面中它不起作用。 It seems to be refreshing only and not redirecting.它似乎只是令人耳目一新而不是重定向。 Here is my code for the button:这是我的按钮代码:

<asp:Button ID="btnCancelValidatePassword" runat="server" 
                        CausesValidation="False" ClientIDMode="AutoID" CssClass="ButtonControl" 
                        Height="30px" OnClientClick="window.location.replace('../Account/Settings.aspx')" Text="CANCEL" Width="100px" />

Thanks.谢谢。

I had an issue with it not working when reloading same page in Chrome .Chrome中重新加载同一页面时,我遇到了它无法正常工作的问题。 Doing the following worked:执行以下操作:

   window.location.replace("/mypage1.aspx?type=abc"); //redirect to fake page
   window.location.replace("/mypage.aspx?type=abc");  //redirect to same page

It is a bit of a hack, but this seems to be the only thing that forces a reload on the same page in Chrome.这有点像 hack,但这似乎是唯一在 Chrome 中强制重新加载同一页面的东西。 IE and FF work without the redirect to a fake page. IE 和 FF 无需重定向到虚假页面即可工作。

.replace() is a method of the String object .replace()String对象的一个​​方法

window.location is not a string. window.location不是字符串。 Use window.location.href instead and call .replace() on window.location.href .改用window.location.href并在window.location.href上调用.replace()

window.location.href.replace(/string_to_be_replaced/, 'string_to_replace');

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

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