2015-02-06 60 views
1

我有這樣的URL我怎樣才能得到基本主機的角度JS

https://192.168.0.10/users/#!/user-profile/20

$ location.host是給我192.168.0.10

我想只得到

https://192.168.0.10

我怎樣才能得到

+0

location.host不應該給你那個。爲什麼會給協議?您需要組合主機加協議。只需在Chrome中打開控制檯(f12)並打開網頁並鍵入'location',看看它顯示的內容 – PSL 2015-02-06 01:40:53

+0

請注意,location.origin在IE中不工作(直到11)。 $位置只是一個包裝 – PSL 2015-02-06 01:46:36

+0

@PSL謝謝,我從控制檯得到。 – user3214546 2015-02-06 01:48:34

回答

1

你可以做一件事: -

var protocol = $location.protocol(); 
var host = $location.host(); 

var combined = protocol + '://' + host;