yelo3 yelo3 - 1 year ago 120
Javascript Question

Get protocol,domain and port from URL

I need to extract the full protocol, domain and port from a given URL. For example:


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download