简体   繁体   English

JavaScript 将用户重定向到新页面

[英]JavaScript redirect user to new page

I am working on a web app using Firebase and Vanilla JavaScript.我正在使用 Firebase 和 Vanilla JavaScript 开发 web 应用程序。 Let's say I have home page index.html, when user clicks to sign in, a popup appears where he will enter details.假设我有主页索引.html,当用户单击登录时,会出现一个弹出窗口,他将在其中输入详细信息。 Since he signs in it means the URL should be localhost:5000/signin .由于他登录,这意味着 URL 应该是localhost:5000/signin signin 。 Is it possible to do it with JavaScript from frontend or is there a need to add Node.js to redirect user respectively.是否可以从前端使用 JavaScript 或是否需要添加 Node.js 来分别重定向用户。 I am confused how this works and would appreciate if someone could explain how should I approach this.我很困惑这是如何工作的,如果有人能解释我应该如何处理这个问题,我将不胜感激。

You can change the url without changing or reloading the page in modern browsers.您可以更改 url 而无需在现代浏览器中更改或重新加载页面。

window.history.pushState({}, 'Signin', '/signin');

Or you can use replaceState since you are using modal, however it will break back button functionality.或者您可以使用 replaceState,因为您使用的是模式,但是它会中断按钮功能。

Please look at pushState请看pushState

This will work:这将起作用:

<script>
    function signin() {
        window.open("/signin", "_blank", "width=500,height=300")
    } 
</script>

You can change width and height to your sign-in page width and height.您可以将宽度和高度更改为登录页面的宽度和高度。 Also, you can add some other properties to your popup.此外,您可以在弹出窗口中添加一些其他属性。 For more information visit https://www.w3schools.com/jsref/met_win_open.asp This also might be helpful if you want to make your page maximized How to open maximized window with Javascript?欲了解更多信息,请访问https://www.w3schools.com/jsref/met_win_open.asp如果您想让您的页面最大化,这也可能会有所帮助如何使用 Z9E13B69D1D14DA927Z102ACAAAF 打开最大化的 window?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM