I have domain name for eq.
1) http://www.abc.com/search
2) http://go.abc.com/work
I get only domain name from the above URL
Output
Try like this.
var hostname = window.location.origin
If the URL is "http://example.com/path" then you will get "http://example.com" as the result.
This won't work for local domains
When you have URL like "https://localhost/MyProposal/MyDir/MyTestPage.aspx"
and your virtual directory path is "https://localhost/MyProposal/"
In such cases, you will get "https://localhost".