由于某些原因,document.location.href
、window.location.href
和 window.location.replace
不工作,我现在正在使用 localhost,我不知道如何将它重定向到另一个网页。我尝试在前面添加 http://,它仍然不起作用,我尝试将其重定向到另一个在线网站,它也没有用。我已经阅读了很多线程并尝试了它们,但它们都不适合我。
var loginBut = document.getElementById("RDbtn1");
loginBut.addEventListener("click", checklogin);
function check(){
document.location.href = "http://localhost/some/directory/here";
alert(document.location.origin + '/some/directory'); // I just use this to know that the button is being pressed.
}
html:
<!-- some code here-->
<li><button class="login1" id="RDbtn1">LOGIN</button></li>
<!-- some code here -->
最佳答案
我相信你应该重定向到特定的 html 页面并且应该给出你的本地主机应用程序正在运行的端口
document.location.href = "http://localhost:8080/some/directory/here/file.html";
关于javascript - 我怎样才能转到另一个 HTML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66838866/