You are here: Home → Table of contents → Common Patterns → Getting the current domain name
4.18. Getting the current domain name
User scripts that operate on multiple domains (or all domains) frequently need to detect the domain of the current page.
You can use window.location.href to get the full URL of the current page, or window.location.host to get just the domain name by itself.
Example: Get the current domain
var href = window.location.host;