The hash property of a WorkerLocation object returns the hash (fragment) part of the worker’s location. Learn self.location.hash, the string return value, how it differs from search and the page’s window.location.hash—with five examples and try-it labs.
01
Kind
Instance property
02
Returns
String
03
Access
self.location
04
Writable?
Read-only
05
Context
Web Workers only
06
Status
Baseline widely
Fundamentals
Introduction
Inside a Web Worker, self.location is a WorkerLocation—the absolute URL of the script that worker is running. The hash property is the fragment after #, just like the familiar page API, but scoped to the worker script URL, not the HTML page.
MDN’s classic example: on a worker loaded from a URL ending in #examples, location.hash returns "#examples".
💡
Beginner tip
You cannot read WorkerLocation from the main page. Start a worker, read location.hashinside it, then postMessage the value back if the UI needs it.
Concept
Understanding the hash Property
A read-only instance property on WorkerLocation that returns the hash part of the worker’s location as a string.
Value — a string (includes leading # when a fragment exists).
Empty fragment — "" when the worker URL has no hash.
Access — self.location.hash or location.hash inside the worker.
Workers only — not available on the main document thread.
Baseline Widely available on MDN (since July 2015).
Foundation
📝 Syntax
Read the property inside a worker script:
JavaScript
const result = location.hash;
// e.g. "#examples" when the worker URL ends with #examples
Value
A string.
Typical pattern (MDN idea)
JavaScript
// Inside a Web Worker whose URL includes #examples
const result = location.hash; // "#examples"
self.postMessage(result);
Compare
⚖️ hash vs Related Ideas
Idea
Meaning
location.hash (worker)
Fragment of the worker script URL
window.location.hash
Fragment of the page URL (main thread)
location.search
Query string (?…), not the fragment
location.href
Full serialized worker URL
location.pathname
Path only (no query / hash)
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Read hash
self.location.hash
Return type
String
No fragment
""
Pass fragment into worker
new Worker(url + "#examples")
Send to main
self.postMessage(location.hash)
MDN status
Baseline Widely available (since July 2015)
Snapshot
🔍 At a Glance
Four facts to remember about WorkerLocation.hash.
Returns
string
Often "#id"
Where
in worker
self.location
Writable
no
Read-only
Baseline
widely
Since Jul 2015
Hands-On
Examples Gallery
Examples follow MDN WorkerLocation.hash. Labs use blob workers and append #… to the worker URL so location.hash is easy to see.
📚 Getting Started
Read the fragment the MDN way.
Example 1 — Read location.hash (MDN Idea)
When the worker URL ends with #examples, the property returns that fragment.
WorkerLocation.hash is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. It is only available in Web Workers.
✓ Baseline · Widely available
WorkerLocation.hash
Returns the hash part of the worker's location as a string. Read it with self.location.hash inside a worker.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerWorkers / WorkerLocation in IE10+ (prefer modern browsers)
Legacy
WorkerLocation.hashExcellent
Bottom line: Read location.hash inside the worker—append #fragment to the Worker URL when you need a non-empty value in demos.
Wrap Up
Conclusion
WorkerLocation.hash is the worker-side fragment string for the script URL. Read it with location.hash inside the worker, remember it is read-only, and post it to the main thread when the UI needs the value.
Keep hash and search roles clear in your URL design
❌ Don’t
Expect WorkerLocation on the main thread
Assign to location.hash in a worker (read-only)
Confuse page window.location.hash with the worker’s hash
Assume blob workers always have a fragment
Put secrets in the fragment—URLs can be logged
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about WorkerLocation.hash
The fragment of the worker script URL, as a string.
5
Core concepts
🔗01
Returns
string fragment
API
⚙️02
Workers
self.location
Context
🔒03
Read-only
no assign
Rule
💬04
postMessage
send to main
Pattern
🎯05
Baseline
since Jul 2015
Status
❓ 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".
Did you know?
WorkerLocation is initialized for each worker and exposed as self.location. It mirrors many ideas from page Location, but it is a separate interface that exists only inside worker scripts.