2012-07-17 59 views
0

我有這個文件夾結構內的PHP文件:定位對象中的JavaScript

頁面 - >腳本 - > gen.php

從這個gen.php我想在JavaScript中location()功能重定向到

基於Web>的Index.html

我試圖做這樣的:

location = "localhost/Web/index.html" 

但我只得到一個404 error說這條路徑是無效的。什麼是正確的方法來做到這一點?

+2

你需要指定的協議。 'location =「http://localhost/Web/index.html」' – 2012-07-17 12:38:01

回答

4

location在JavaScript中不是函數。這是一個屬性,您可以分配一個值。

任何的(假設網絡暴露在URL,而不是隻是一個內部目錄):

  • http://localhost/Web/index.html
  • //localhost/Web/index.html
  • /Web/index.html
  • index.html

然而,通常應該使用HTTP處理重定向,所以你是李(請注意,雖然大多數瀏覽器將從位置標題中的相對URI恢復,但該規範要求絕對URI)。

2

改爲寫location = "http://localhost/Web/index.html"。你錯過添加http://

OR location = "index.html"如果你是在同一個目錄