just wanna ask why does window.location.replace is not working in my page. 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. 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 . 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. IE and FF work without the redirect to a fake page.
.replace()
is a method of the String
object
window.location
is not a string. Use window.location.href
instead and call .replace()
on window.location.href
.
window.location.href.replace(/string_to_be_replaced/, 'string_to_replace');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.