我如何将用户从一个页面转向另一个页面,使用jQuery或纯粹的JavaScript?


当前回答

您可以写下按钮点击事件的 URL.Action 在脚本部分如下。

function onclick() {
    location.href = '@Url.Action("Index", "Home")';
}

其他回答

您可以使用 window.location 设置。

例子:

window.location = "https://stackoverflow.com/";

此分類上一篇: 我如何轉向另一個網站?

如果您想在同一应用程序中重新引导到路线

window.location.pathname = '/examplepath'

这将是走路的方式。

在您的点击功能上,只需添加:

window.location.href = "The URL where you want to redirect";
$('#id').click(function(){
    window.location.href = "http://www.google.com";
});

JavaScript 是非常广泛的. 如果你想跳到另一个页面,你有三个选项。

 window.location.href='otherpage.com';
 window.location.assign('otherpage.com');
 //and...

 window.location.replace('otherpage.com');

当你想移动到另一个页面,你可以使用其中一个,如果这是你的要求. 但是,所有三个选项都限于不同的情况。

如果你有兴趣了解更多关于这个概念,你可以通过更多。

window.location.href; // Returns the href (URL) of the current page
window.location.hostname; // Returns the domain name of the web host
window.location.pathname; // Returns the path and filename of the current page
window.location.protocol; // Returns the web protocol used (http: or https:)
window.location.assign; // Loads a new document
window.location.replace; // RReplace the current location with new one.

jQuery 不需要,你可以这样做:

window.open("URL","_self","","")

这是那么容易的!

启动 HTTP 请求的最佳方式是使用 document.loacation.href.replace(‘URL’)。