WorkerLocation.hash returns the hash (fragment) part of the worker’s location as a string. Per MDN, if the worker URL ends with #examples, location.hash is "#examples".
Read the notes below before you rely on this property. Prefer feature detection when support is limited.
Syntax
Use location.hash. Start with this line.
JavaScript
location.hash
Call
What it does
location.hash
Primary signature.
Built into Web Workers. Read self.location.hash (or location.hash) inside a worker — no import required.
Library declarations
JavaScript
location.hash
Parameters
Parameter
Description
Worker context
Required. self.location is a WorkerLocation
Fragment on Worker URL
Optional. Needed for a non-empty hash
Return Value
Return Value
Description
*
String ("#…" or "")
JavaScript Examples
Example 1 — Read location.hash
When the worker URL ends with #examples, the property returns that fragment (MDN idea).
JavaScript
// Worker URL ends with #examples
const result = location.hash; // "#examples"
self.postMessage(result);
Read the raw fragment. Browsers include the leading # when present.
Detect the prefix.startsWith("#") is a clear check (works for "" too).
Slice once.slice(1) drops the first character → "examples".
Use the bare id. Compare or switch on id without worrying about #.
Compatibility
Browser Support
WorkerLocation.hash is marked Baseline Widely available on MDN (since July 2015). It is only available in Web Workers — not in Node.js, Bun, or Deno.
✓ Baseline · Widely available
WorkerLocation.hash
Supported across modern browsers with Web Workers. Read location.hash inside the worker.
98%Browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
WorkerLocation.hashExcellent
Bottom line: Browser / Web Workers only — not a Node.js API. Append #fragment to the Worker URL when demos need a non-empty hash.
Frequently Asked Questions
A string: the hash (fragment) part of the worker’s location URL—including the leading # when a fragment is present. Access it inside a worker as self.location.hash or location.hash.
No. MDN marks WorkerLocation.hash as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is only available in Web Workers.
Same idea (URL fragment), different object. Inside a worker you read WorkerLocation via self.location—not the page’s Location. Also, WorkerLocation.hash is read-only.
If the worker script URL has no fragment, location.hash is the empty string "" (not null).
No. WorkerLocation.hash is read-only. You cannot navigate or rewrite the worker URL by assigning to hash the way you might on window.location.
Pass a fragment on the Worker URL, for example new Worker(blobUrl + "#examples"). Inside the worker, location.hash is then "#examples".