Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从默认主页重定向到索引页?_Javascript_Html_Redirect - Fatal编程技术网

Javascript 如何从默认主页重定向到索引页?

Javascript 如何从默认主页重定向到索引页?,javascript,html,redirect,Javascript,Html,Redirect,假设你有一个网站example.com。如果您在搜索栏中键入example.com,您将被带到该站点的索引页。但是,此页面在技术上与example.com/index.html不同 var currentPage = window.location.href 我在一些条件语句中使用上述JS方法来确定当前页面并相应地调整格式,但由于example.com和example.com/index.html之间的差异,它无法工作,那么,我将如何执行这种重定向呢?向我们展示一个实际重现问题的代码示例。您使

假设你有一个网站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";