JavaScript window.location函数在localhost文件夹中不起作用

时间:2023-01-16 21:41:52

In htdocs directory of xampp i have created a list directory and place a simple index.html file in it.

在xampp的htdocs目录中,我创建了一个列表目录,并在其中放置了一个简单的index.html文件。

The file contain

该文件包含

<!Doctype html>
<html>
   <head>
  <script>
        function Redirect() {
        alert("file:///D:/xampp/htdocs/");
           window.location="file:///D:/xampp/htdocs/";
        }
  </script>
</head>
    <body onload="Redirect();">
   </body>
</html>

When i navigate to localhost/list/ it is showing a blank page, and when i have open it directly with any browser it's working fine.

当我导航到localhost / list /时它显示一个空白页面,当我用任何浏览器直接打开它时它工作正常。

Is there any restriction with this url "file:///D:/xampp/htdocs/".

这个URL“file:/// D:/ xampp / htdocs /”是否有任何限制。

I want to see File Structure with file:// url.

我希望看到文件结构与file:// url。

3 个解决方案

#1


0  

you can try this one:

你可以尝试这个:

<script>
        function Redirect() {
        alert("../xampp/htdocs/");
           window.location="../xampp/htdocs/";
        }
  </script>

#2


0  

If you're already in the xampp subdir, use a relative URL:

如果您已经在xampp子目录中,请使用相对URL:

<!Doctype html>
<html>
   <head>
  <script>
        function Redirect() {
        alert("./htdocs/");
           window.location="./htdocs/";
        }
  </script>
</head>
    <body onload="Redirect();">
   </body>
</html>

#3


0  

Simpler way to achieve this:

更简单的方法来实现这一目标:

<!Doctype html>
<html>
   <head>
   <script>
        function Redirect() {
           alert("htdocs directory here");
           window.location="http://localhost/";
        }
   </script>
   </head>
   <body onload="Redirect();">
   </body>
</html>

as htdocs will internally call localhost

因为htdocs会在内部调用localhost

#1


0  

you can try this one:

你可以尝试这个:

<script>
        function Redirect() {
        alert("../xampp/htdocs/");
           window.location="../xampp/htdocs/";
        }
  </script>

#2


0  

If you're already in the xampp subdir, use a relative URL:

如果您已经在xampp子目录中,请使用相对URL:

<!Doctype html>
<html>
   <head>
  <script>
        function Redirect() {
        alert("./htdocs/");
           window.location="./htdocs/";
        }
  </script>
</head>
    <body onload="Redirect();">
   </body>
</html>

#3


0  

Simpler way to achieve this:

更简单的方法来实现这一目标:

<!Doctype html>
<html>
   <head>
   <script>
        function Redirect() {
           alert("htdocs directory here");
           window.location="http://localhost/";
        }
   </script>
   </head>
   <body onload="Redirect();">
   </body>
</html>

as htdocs will internally call localhost

因为htdocs会在内部调用localhost