Home » Categories » JavaScript

Get The Current Domain Name With Javascript (Not the path, etc.)

 

If you wish a full domain origin, you can use this:

document.location.origin

And if you wish to get only the domain, use can you just this:

document.location.hostname

But you have other options, take a look at the properties in:

document.location


Reference:
https://stackoverflow.com/questions/11401897/get-the-current-domain-name-with-javascript-not-the-path-etc/11401921
Article Rating (No Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
  • Icon Bookmark Bookmark Article (CTRL-D)
 
Attachments Attachments
There are no attachments for this article.
Comments Comments
There are no comments for this article. Be the first to post a comment.
Related Articles RSS Feed
Strip HTML Tags in JavaScript
Viewed 561 times since Sat, Oct 3, 2020
Check image width and height before upload with Javascript
Viewed 535 times since Mon, Sep 21, 2020
Hidden image after redirect by check filename
Viewed 632 times since Wed, Sep 30, 2020
Regex in Javascript to remove links
Viewed 537 times since Sat, Oct 3, 2020
How to hide image broken Icon using only CSS/HTML?
Viewed 814 times since Wed, Sep 30, 2020
XMLHttpRequest.responseURL
Viewed 526 times since Wed, Sep 30, 2020