假设您有一个网站 example.com。如果您在搜索栏中输入 example.com,您将被带到该网站的索引页面。但是,从技术上讲,此页面与 example.com/index.html 不同。
var currentPage = window.location.href
我在一些条件语句中使用上面的JS方法来确定当前页面并相应地调整格式,但是由于example.com和example.com/index.html之间的差异,它不起作用,那么我将如何执行这种重定向?
最佳答案
// Similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");
// Similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";
关于javascript - 如何从默认主页重定向到索引页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49345818/