[英]Redirecting in ASP.NET MVC using Javascript or something else the best way?
I have a confirm box and redirect to an action but it is not working.. 我有一个确认框,并重定向到某个操作,但是它不起作用。
<script type="text/javascript">
function quitProgram()
{
var answer = confirm("Are you sure you want to quit your current program?");
if (answer)
window.location("http://www.google.com");
else
window.location("http://www.yahoo.com");
}
</script>
Html Code - HTML代码-
<input style="float:right;" type="submit" value="Quit Program" id="QuitProgram" onclick="quitProgram()" />
But the redirect never happens...can anyone help me with this..ultimately what i want to do is redirect to an action based on user response...it would be great if anyone lets me know the best way i should do this? 但是重定向永远不会发生...任何人都可以帮我解决这个问题..最后我想做的就是根据用户响应重定向到某个操作...如果有人让我知道我应该这样做的最佳方式,那将是非常不错的?
window.location is a property not a method: window.location是属性而不是方法:
if (answer)
window.location = "http://www.google.com";
else
window.location = "http://www.yahoo.com";
Stuart identified one problem with the code posted in the question. Stuart 用问题中张贴的代码确定了一个问题 。 One more thing you'll have to do is change the
input
element's type from "submit" to "button", or the submit will cause a post that will override the redirect. 您还需要做的另一件事是将
input
元素的类型从“提交”更改为“按钮”,否则提交将导致发布将覆盖重定向的帖子。
I am not sure but try this 我不确定,请尝试一下
function quitProgram()
{
var answer = return confirm("Are you sure you want to quit your current program?");
if (answer)
window.location("http://www.google.com");
else
window.location("http://www.yahoo.com");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.