使用jQuery或纯 JavaScript 如何将用户从一页转到另一页?


当前回答

单页应用在同一申请路线内

window.location.pathname = '/stack';

JavaScript :

location.href = "http://stack.com";
window.location = "http://stack.com";

jj 查询 :

$(location).attr('href', "http://www.stack.com");
$(window).attr('location', "http://www.stack.com");

角形 4

import { Router } from '@angular/router';
export class NavtabComponent{
    constructor(private router: Router) {
    }
    this.router.navigate(['bookings/taxi']);
}

其他回答

根据我的工作经验 JavaScript 更适合重新定位

它取决于您要如何更改地址。 如果您想要在用户历史中登录您的网站, 请使用window.location.href='ur website';否则在不记录历史的情况下使用window.location.replace("your website");.

但如果有人想重回主页 他可能会使用下面的片段

window.location = window.location.host

如果你有三种不同的环境,如发展、中转和生产,将会很有帮助。

您可以将这些单词放入铬控制台, 来探索此窗口或窗口。 位置对象 。 @ info: whatsthis火虫控制台

每个浏览器都使用此功能 :

window.location.href = 'your_url';

这很容易执行。 您可以使用 :

window.location.href = "http://www.example.com/";

这将记住上一页的历史。 这样可以点击浏览器的后键返回历史 。

或者:

window.location.replace("http://www.example.com/");

此方法不记得上一页的历史。 在此情况下, 后端按钮会被禁用 。

这是重定向到其他页面的代码 超过10秒的超时

<script>
    function Redirect()
    {
        window.location="http://www.adarshkr.com";
    }

    document.write("You will be redirected to a new page in 10 seconds.");
    setTimeout('Redirect()', 10000);
</script>

您也可以这样操作, 点击按钮时使用位置. 指派 :

<input type="button" value="Load new document" onclick="newPage()">
<script>
    function newPage() {
        window.location.assign("http://www.adarshkr.com")
    }
</script>