Rahul February 2016

JavaScript window.location function not working in localhost folder

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

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.

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

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

Answers


Ivin Raj February 2016

you can try this one:

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


Axel Amthor February 2016

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

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


Munjal Mayank February 2016

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

Post Status

Asked in February 2016
Viewed 1,362 times
Voted 4
Answered 3 times

Search




Leave an answer