重定向一个新的页面按钮点击

redirecting a new page on button click

本文关键字:按钮 一个 重定向      更新时间:2023-09-26

我正在尝试重定向到同一目录下的新页面,在页面中单击按钮。

目录结构:main(folder) --> index.html, home.html

index.html有登录部分按钮点击我想让页面转到home.html。

$('#login').click( function() {         
        var user = $("#user").val(); 
        var pass = $("#pass").val(); 
        if(user == "xyz" && pass =="testing1"){
        location.href('home.html');
        }else{alert("invalid credits")}
    });
window.location = window.location.href.replace("index.html","home.html");

使用

window.location = "put url here"

try

window.location.href('home.html');

试试这个:

$('#login').click(function(){
  ...........
  document.location.href='the_link_to_go_to.html';
})

window.location.replace(...)最能模拟HTTP重定向

如果您想模拟HTTP重定向,请使用location.replace

window.location.href = 'the_link';
window.location.replace("the_link");

请使用window.location.href

window.location.href='home.html'