script"
(2 intermediate revisions by 2 users not shown) | |||
Line 7: | Line 7: | ||
[since 3.6.2] | [since 3.6.2] | ||
− | It tells ZK to generate a < | + | It tells ZK to generate a <code><script></code> inside <code><head></code> '''after ZK default JavaScript and CSS files'''. Thus, it can be used to override what is defined in ZK default JavaScript code. Currently only HTML-based clients (so-called browsers) support it. Furthermore, HTML SCRIPT tag is actually generated for each of this declaration. |
− | Developers can specify whatever attributes you like; it is up to the browser to interpret. ZK only evaluates the <code>if</code> and <code>unless</code> attributes, and encodes the URI of the < | + | Developers can specify whatever attributes you like; it is up to the browser to interpret. ZK only evaluates the <code>if</code> and <code>unless</code> attributes, and encodes the URI of the <code>href</code> and <code>src</code> attribute (by use of by use of <javadoc method="encodeURL(java.lang.String)">org.zkoss.zk.ui.Execution</javadoc>). ZK generates all other attributes directly to the client. |
− | < | + | <syntaxhighlight lang="xml" > |
<?script src="/js/foo.js"?> | <?script src="/js/foo.js"?> | ||
<?script content="var foo = true; | <?script content="var foo = true; | ||
Line 21: | Line 21: | ||
My content | My content | ||
</window> | </window> | ||
− | </ | + | </syntaxhighlight> |
As shown above, the attribute value could span multiple lines. | As shown above, the attribute value could span multiple lines. | ||
Line 30: | Line 30: | ||
= Limitation = | = Limitation = | ||
− | Notice that these header directives are effective only when you visit the page directly. In other words, they are ignored if a page is included by another page (< | + | Notice that these header directives are effective only when you visit the page directly. In other words, they are ignored if a page is included by another page (<code><include></code>) or servlets. Also, they are ignored if the page is a <code>zhtml</code> file. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{{ZUMLReferencePageFooter}} | {{ZUMLReferencePageFooter}} |
Revision as of 04:26, 5 August 2022
Syntax:
<?script [type="text/javascript"] [src="uri"] [charset="encoding"] [content="javascript snippet"] [if="..."] [unless="..."]?>
[since 3.6.2]
It tells ZK to generate a <script>
inside <head>
after ZK default JavaScript and CSS files. Thus, it can be used to override what is defined in ZK default JavaScript code. Currently only HTML-based clients (so-called browsers) support it. Furthermore, HTML SCRIPT tag is actually generated for each of this declaration.
Developers can specify whatever attributes you like; it is up to the browser to interpret. ZK only evaluates the if
and unless
attributes, and encodes the URI of the href
and src
attribute (by use of by use of Execution.encodeURL(String)). ZK generates all other attributes directly to the client.
<?script src="/js/foo.js"?>
<?script content="var foo = true;
if (zk.ie) doSomething();"?>
<window title="My App">
My content
</window>
As shown above, the attribute value could span multiple lines.
Alternatives
Alternatively, you could use the script component to embed JavaScript code. The script component supports more features such as defer, but it has some memory foot print at the server (since it is a component).
Limitation
Notice that these header directives are effective only when you visit the page directly. In other words, they are ignored if a page is included by another page (<include>
) or servlets. Also, they are ignored if the page is a zhtml
file.