【问题标题】:window.location.replace() is not workingwindow.location.replace() 不起作用
【发布时间】:2013-02-10 09:10:47
【问题描述】:

只是想问一下为什么 window.location.replace 在我的页面中不起作用。我已经为此工作了好几个星期。它在我的其他页面上运行良好,虽然这些页面有 DevExpress 组件,但是在这个我只使用普通 html 和 asp 标签和组件的特定页面中它不起作用。它似乎只是令人耳目一新而不是重定向。这是我的按钮代码:

<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" />

谢谢。

【问题讨论】:

  • 如果您使用的是 firefox,请打开错误控制台 (CTRL+SHIFT+J)...您是否看到任何错误?
  • 嗨,我收到了很多警告和 2 个错误:(1) TypeError: defaultEngine is null (2) AboutHomeUtils.defaultSearch is undefined
  • 修复该错误,或​​者您可以在您的问题中发布错误,以便其他人可以帮助您。
  • 我的页面位于安全窗口中。跟我的问题有关系吗?

标签: javascript asp.net redirect


【解决方案1】:

Chrome 中重新加载同一页面时,我遇到了无法正常工作的问题。执行以下操作:

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

这有点像 hack,但这似乎是在 Chrome 中强制重新加载同一页面的唯一方法。 IE 和 FF 无需重定向到虚假页面即可工作。

【讨论】:

    【解决方案2】:

    .replace()String 对象的一个​​方法

    window.location 不是字符串。请改用window.location.href 并在window.location.href 上调用.replace()

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

    【讨论】:

    猜你喜欢
    • 2018-07-06
    • 1970-01-01
    • 2021-03-24
    • 2023-01-13
    • 1970-01-01
    • 2013-06-14
    • 2016-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多