当前网址是
每当单击取消按钮需要从位于另一个文件夹中的不同操作结果导航时,我的页面中就有取消按钮
例如:关于/结果(即 http://xx.com/About/Result)我的取消函数中有以下代码
function cancel() {
window.location = '@Url.Action("Result", "About")';
return false;
}
所有的方法都试过了
window.location.href= "/About/Result"
window.location.pathname="/About/Result"
但它仍然没有改变旧值。它只保留旧值。
引用了很多类似的链接
window.location.href does not change the URL
https://developer.mozilla.org/en-US/docs/Web/API/Window.location
但当我尝试给予
window.location.href="http://www.google.com"
它工作正常。为什么我不能从一个 Action 导航到不同目录中的另一个 Action 。有什么问题吗?
确切的根本原因是什么?
最佳答案
引用以下链接找到解决方案
windows.location.href not working on Firefox3
需要添加return like
<button id="btnCancel" class="btn" onclick="return cancel()">
在您的页面标记中,点击时调用此函数的控件必须返回此函数的值。
function cancel() {
window.location.href = "../../About/Index";
return false;
}
关于javascript - window.location 或 window.location.href 不更改所有浏览器 MVC 应用程序中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21182019/