Get protocol, domain, and port from URL Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Get protocol, domain, and port from URL without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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

Answer

first get the current address

var url = window.location.href

Then just parse that string

var arr = url.split("/");

your url is:

var result = arr[0] + "//" + arr[2]

Hope this helps

We are here to answer your question about Get protocol, domain, and port from URL - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji