What the hash does in Dglux5 and why you need it
The hash in a web document is the part of the URL that comes after the # symbol — for example, yoursite.com#section2. In Dglux5, setting the hash lets you create direct links to specific parts of your document, and it lets you control what appears on screen when someone lands on that link. Without setting hashes, every visitor sees the same starting point regardless of what URL they clicked.
Dglux5 uses hashes to track which page or state your document is currently showing. When you set a hash, you're telling Dglux5 which view to display. This matters because it makes your document shareable — someone can send a link that opens directly to the section they want you to see, not to the beginning.
Key Takeaways
- The hash is the #symbol and text at the end of a URL, and Dglux5 uses it to remember which page or view is currently open.
- You set the hash by using the setHash() function in your Dglux5 script, passing the name of the page or state you want to display.
- Hashes must match the exact names of your pages or states in Dglux5, including uppercase and lowercase letters.
- When someone visits a URL with a hash already in it, Dglux5 reads that hash on load and displays the correct page automatically.
- Testing your hash setup in the browser's address bar shows you whether Dglux5 is reading and responding to hash changes correctly.
Finding where to write your hash code in Dglux5
In Dglux5, you write hash commands in the JavaScript panel or in event handlers attached to buttons and other interactive elements. The JavaScript panel is usually on the right side of your Dglux5 workspace, or you can open it through the View menu if it is not visible.
If you are setting a hash when someone clicks a button, right-click the button, select Add Event, choose onClick, and then write your hash code in the event handler that appears. If you want the hash to be set when the document first loads, use the document's onLoad event instead.
Writing the setHash() function
The basic command to set a hash in Dglux5 is setHash("pageName"), where pageName is the exact name of the page or state you want to display. For example, if you have a page called "ContactForm", you would write:
setHash("ContactForm")
This command tells Dglux5 to change the URL hash to #ContactForm and display the page named ContactForm. The name must match exactly — if your page is called "contactform" in lowercase but you write "ContactForm" in uppercase, Dglux5 will not find it and nothing will happen.
You can also set the hash with additional parameters if your Dglux5 setup uses them. Check your document's page names by looking at the Pages panel on the left side of Dglux5 — the names you see there are the exact strings you need to use in setHash().
Connecting hash changes to buttons and user actions
The most common way to set a hash is to attach it to a button click. When someone clicks a button, you want Dglux5 to show a different page and update the URL hash so the link is shareable.
Right-click the button in your Dglux5 canvas, select Add Event, then choose onClick. In the event handler box that opens, type your setHash command. For a button that should show your "Gallery" page, write:
setHash("Gallery")
Now when someone clicks that button, the hash changes to #Gallery, the URL updates, and the Gallery page displays. If you have multiple buttons that navigate to different pages, each button gets its own onClick event with its own setHash command pointing to the correct page name.
Reading the hash when your document loads
When someone visits your document with a hash already in the URL — for example, yoursite.com#Gallery — Dglux5 needs to know to display the Gallery page instead of the default starting page. This happens automatically in most Dglux5 setups, but you can also write code to handle it explicitly.
In the document's onLoad event, you can read the current hash and respond to it. Right-click the document background (not a specific element), select Add Event, choose onLoad, and write code that checks the hash and calls the right page. Many Dglux5 documents handle this automatically through their routing system, so check your document's existing code first before adding your own.
If your document does not automatically respond to hashes on load, you may need to add a line like setHash(window.location.hash.substring(1)) in the onLoad event, which reads the hash from the URL and passes it to setHash(). The substring(1) part removes the # symbol so Dglux5 gets just the page name.
Testing your hash setup in the browser
After you set up your hash commands, open your Dglux5 document in a web browser and test it. Click the buttons that should trigger hash changes and watch the URL bar — you should see the hash change from nothing to #PageName when you click.
If the hash does not change, check that your page name in setHash() matches exactly what appears in the Pages panel. Capitalization matters. If the hash changes but the page does not display, your Dglux5 document may not be set up to respond to hash changes on load — in that case, you may need to add the onLoad code mentioned in the previous section.
You can also manually type a hash into the URL bar to test. If your document is at localhost:8080/mydoc, try changing it to localhost:8080/mydoc#Gallery and pressing Enter. If your setup is working, the Gallery page should display automatically.
Common mistakes and how to fix them
The most frequent error is a mismatch between the page name you write in setHash() and the actual page name in your Pages panel. If you write setHash("gallery") but your page is named "Gallery" with a capital G, nothing will happen. Copy the exact page name from the Pages panel and paste it into your setHash command to avoid typos and case mismatches.
Another common issue is forgetting to attach the hash command to an event. Writing setHash() in the JavaScript panel without attaching it to a button click or page load event means it runs once when you test but does not respond to user actions. Always attach hash commands to specific events — onClick for buttons, onLoad for document startup, or other events depending on what should trigger the change.
If your hash changes but the page does not display, your document may not have routing set up to respond to hash changes. Some Dglux5 documents require additional setup to listen for hash changes and display the correct page. Check whether your document has a routing system already in place, or ask whether you need to add a listener that watches for hash changes and calls the right page display function.
Frequently Asked Questions
Can I use a hash to pass data to a page, not just show a page name?
Yes, but it depends on your Dglux5 setup. You can write something like setHash("Gallery?id=5") to pass additional information, but your document needs code to read and use that data. Basic setHash() just shows pages by name, so check your document's routing system to see whether it supports passing parameters through the hash.
What if I want the hash to change without showing a different page?
You can call setHash() without it triggering a page change if your document does not have routing set up. This is useful for bookmarking a state or scroll position. However, most Dglux5 documents are set up so that changing the hash automatically changes the page, so test your specific document to see how it behaves.
Do I need to set a hash for every page in my document?
No. You only need to set hashes for pages you want to be directly linkable or shareable. If a page is only shown as a result of clicking a button, and you do not need a direct link to it, you do not need a hash. However, setting hashes for all your main pages is a good practice because it makes your document easier to navigate and share.
Why does the hash disappear when I navigate to a new page?
If you are navigating away from your Dglux5 document entirely (to a different website), the hash disappears because you are no longer in the same document. If the hash disappears while staying in your Dglux5 document, your setHash() command may not be running — check that it is attached to the right event and that the page name is spelled correctly.
Can I use special characters or spaces in a hash?
Avoid spaces and special characters in hashes. Use only letters, numbers, hyphens, and underscores. If your page name has spaces, either rename the page to remove them or use hyphens instead (for example, "contact-form" instead of "contact form"). This keeps your URLs clean and prevents encoding issues.