![](/img/trans.png)
[英]Difference between window.location.href, window.location.replace and window.location.assign
[英]window.location.href and window.location.replace() not working
已解決有關此主題的所有問題,但沒有一個解決方案對我有用。
我正在創建一個登錄頁面(恰好是我的index.html
),在身份驗證后,我想將用戶重定向到另一個頁面( football.html
),該頁面存儲在一個名為views
的目錄中。
所以這就是我正在做的事情:
login.addEventListener('click',(e)=>{
var email = document.getElementById('loginEmail').value;
var password = document.getElementById('loginPass').value;
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
const dt = new Date();
update(ref(database, 'users/' + user.uid),{
last_login: dt,
})
alert('User logged in!');
window.location.href = './views/football.html';
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
alert(errorMessage);
});
});
我試過使用window.location.replace('views/football.html');
但在這兩種情況下,重定向都不會發生。
警報后 url 只是更改為http://localhost:1234/views/football.html
但未顯示新頁面。
我認為這是由於警報,但刪除它什么也沒做。
編輯:
試過window.location.href = './views/football.html';
沒用。
試試window.location.replace("your url");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.