从URL获取协议,域和端口 [英] Get protocol, domain, and port from URL
本文介绍了从URL获取协议,域和端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从给定的URL中提取完整的协议,域和端口。例如:
I need to extract the full protocol, domain, and port from a given URL. For example:
https://localhost:8181/ContactUs-1.0/contact?lang=it&report_type=consumer
>>>
https://localhost:8181
推荐答案
首先得到当前地址
var url = window.location.href
然后只需解析该字符串
var arr = url.split("/");
您的网址是:
var result = arr[0] + "//" + arr[2]
希望这有助于
这篇关于从URL获取协议,域和端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文