2012-02-15 131 views
0

如何獲取沒有文檔名稱的文檔路徑?例如:沒有文檔的路徑

window.document.location 

給我:http://host.com/lorem/ipsum/document.php
,我只需要得到:http://host.com/lorem/ipsum/

將是偉大的幫助。

+2

正則表達式或簡單的JavaScript。它與'jQuery'無關' – gdoron 2012-02-15 16:31:34

+0

好吧,我已經刪除了標籤。 – Tomarz 2012-02-15 16:32:27

+0

@gdoron。謝謝。 – 2012-02-15 16:32:34

回答

1
var loc = location.href; 
loc = loc.substring(0, loc.lastIndexOf("/")); 
+0

這個對我很好。謝謝大家! – Tomarz 2012-02-15 17:04:11

1
var path = window.document.location; 
path = path.substr(0, path.lastIndexOf('/')); 
+1

+1。你忘了寫'path.substr ...'我爲你添加了它。 – gdoron 2012-02-15 16:35:03

+0

謝謝。當我看到錯字時,計算機鎖定在我身上。 – crush 2012-02-15 16:38:43