通过javascript在同一选项卡html中打开页面

通过javascript在同一选项卡html中打开页面,javascript,html,Javascript,Html,我试图写一个代码来匹配用户名和密码。如果两者都正确,则必须重定向到新页面,如果错误,则必须发出警告消息。当密码正确并且单击submit时,它会在新选项卡中打开成功消息,我希望它显示在同一选项卡中 function redirectPage(form) { if (form.uname.value == 'test' && form.uname.value == 'test') { window.open('login.html'); } el

我试图写一个代码来匹配用户名和密码。如果两者都正确,则必须重定向到新页面,如果错误,则必须发出警告消息。当密码正确并且单击submit时,它会在新选项卡中打开成功消息,我希望它显示在同一选项卡中

    function redirectPage(form) {
    if (form.uname.value == 'test' && form.uname.value == 'test') {
       window.open('login.html');
    } else {
      alert("Wrong Credentials, Try again")
    } 
PS

不工作

使用此

window.location.replace("login.html");

试过了,那也不行。它只是刷新我的当前页面。你必须在不同的页面上添加此代码。当达到条件时,它将重定向到“login.html”。初始代码在“index.html”上,当达到这一行时,它应该重定向到“login.html”。您的代码中还有其他内容。它应该工作得很好。请在页面上发布其余的HTML和Javascript
window.location.replace("login.html");