Dive Into Greasemonkey

Teaching an old web new tricks

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;

Real examples

← Matching case-insensitive attribute values
Rewriting links →