如何使用javascript获取基本URL?
例如,当我从VisualStudio浏览我的网站时,如果我的URL是http://localhost:20201/home/index
,我想得到http://localhost:20201
如果我把我的网站放在IIS上,如果我的虚拟目录名是MyApp,URL是http://localhost/MyApp/home/index
,我想得到http://localhost/MyApp
我try 使用location.protocol
+location.hostname
(和location.host
),当我通过visual studio浏览我的网站时,它们工作正常,但当我在IIS上托管它时,我得到http://localhost
,/MyApp被截断.