如何使用javascript获取当前URL
我有一个当前的URL:如何使用javascript获取当前URL,javascript,converter,Javascript,Converter,我有一个当前的URL: http://www.test.com/p1234?utm_source=.... 如何获取格式为http://www.test.php/p1234 我正在使用javascriptdocument.URL,结果是http://www.test.com/p1234?utm_source=....您想要: var location = window.location.host + window.location.pathname; 请参阅文档:这是正确答案: window
http://www.test.com/p1234?utm_source=....
如何获取格式为http://www.test.php/p1234
我正在使用javascriptdocument.URL
,结果是http://www.test.com/p1234?utm_source=....
您想要:
var location = window.location.host + window.location.pathname;
请参阅文档:这是正确答案:
window.location.host + window.location.pathname;
还要为使用的协议添加前缀。window.location.protocal+“/”window.location.host+window.location.pathname;