Syntax
goToURLHash ::= Boolean
Description
If the URL of a web page is https://mydomain.org/mydoc.html#myhash
and myhash
exists as a static id in mydoc.html
the browser will show it properly. But if myhash
id is assigned dinamically by ZPT-JS the browser will not find it because it does not exist yet!
If goToURLHash
is true
ZPT-JS forces the browser to show the current hash after rendering the ZPT template. ZPT-JS updates the location.href
to the current URL hash. It is a boolean value.
The default value is true
the first execution of ZPT, the rest executions are default to false
.
Important! This configuration option must be used beside a fullRender or a partialRender command, it will be ignored if the command is another one.
Examples
Let's see an example of ZPT-JS invokation using goToURLHash. We have defined a link like this:
link.html... <a href="sample.html?myId"> My link </a> ...
Our sample HTML document is:
sample.html<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Testing goToURLHash</title> <script src="testingGoToURLHash.js" type="text/javascript" defer></script> </head> <body> ... <div data-attributes="id 'myId'"> ... </div> ... </body> </html>
Now we click the link in link.html
. Before invoking zpt.run
the selected div element does not define any id attribute, so the browser can not find it. But if goToURLHash is true
ZPT-JS updates the location.href
to the current URL hash (myId in this case).
"use strict"; var zpt = require( 'zpt' ); var dictionary = { ... }; zpt.run({ root: document.getElementById( 't1' ), dictionary: dictionary, goToURLHash: true // Force going to URL hash });
This setting is not needed if we want to update location only the first time.