script"

From Documentation
(Created page with '{{ZUMLReferencePageHeader}} <syntax lang="xml" > <?script type="text/javascript" [src="uri"] [charset="encoding"] [content="javascript"] [if="..."] [unless="..."]?> </syntax>…')
 
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{ZUMLReferencePageHeader}}
 
{{ZUMLReferencePageHeader}}
<syntax lang="xml" >
 
<?script type="text/javascript" [src="uri"] [charset="encoding"]
 
  [content="javascript"] [if="..."] [unless="..."]?>
 
</syntax>
 
  
[since 3.6.2]
+
{{versionSince| 3.6.2}}
  
It specifies an element that shall be generated inside the HEAD element. It is generated ''after' ZK default JavaScript and CSS files. Currently only HTML-based clients (so-called browsers) support them. Furthermore, HTML SCRIPT tag is actually generated for each of this declaration.
+
'''Syntax:'''
 +
<?script [type="text/javascript"] [src="''uri''"] [charset="''encoding''"]
 +
  [content="''javascript snippet''"] [if="..."] [unless="..."]?>
  
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 <tt>href</tt> and <tt>src</tt> attribute (by use of the <tt>encodeURL</tt> method of the <tt>Executions</tt> class). ZK generates all other attributes directly to the client.
 
  
Notice that these header directives are effective only for the main ZUL page. In other words, they are ignored if a page is included by another pages or servlets. Also, they are ignored if the page is a <tt>zhtml</tt> file.
 
  
<syntax lang="xml" >
+
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, an HTML SCRIPT tag is generated for each of these declarations.
<?script type="text/javascript" src="/js/foo.js"?>
+
 
<?script type="text/javascript" content="var foo = true;
+
You 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 <javadoc method="encodeURL(java.lang.String)">org.zkoss.zk.ui.Execution</javadoc>). So you can specify an absolute or relative path. ZK generates all other attributes directly to the client.
if (zk.ie) doSomething();"?>
+
 
 +
 
 +
 
 +
<syntaxhighlight lang="xml" >
 +
<?script src="/js/foo.js"?>
 +
<?script content="var foo = true; if (zk.ie) doSomething();"?>
  
 
  <window title="My App">
 
  <window title="My App">
 
     My content
 
     My content
 
  </window>
 
  </window>
</syntax>
+
</syntaxhighlight>
 +
 
 +
As shown above, the attribute value could span multiple lines.
 +
 
 +
=Alternatives=
  
==Alternatives==
+
Alternatively, you could use [[ZK_Component_Reference/Essential_Components/Script|the script component]] to embed JavaScript code. The script component supports more features such as defer, but it has some memory footprint at the server (since it is a component).
  
Alternatively, you could use [[ZK_Component_Reference/Essential_Components/Script|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: Ignored by Inclusion =
 +
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 with <code><include></code>, <code><apply></code>, or servlets API. Also, they are ignored if the page is a <code>zhtml</code> file.
  
==Version History==
 
  
{| border='1px' | width="100%"
 
! Version !! Date !! Content
 
|-
 
| &nbsp;
 
| &nbsp;
 
| &nbsp;
 
|}
 
  
 
{{ZUMLReferencePageFooter}}
 
{{ZUMLReferencePageFooter}}

Latest revision as of 06:00, 21 December 2023

Since 3.6.2

Syntax:

<?script [type="text/javascript"] [src="uri"] [charset="encoding"]
 [content="javascript snippet"] [if="..."] [unless="..."]?> 


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, an HTML SCRIPT tag is generated for each of these declarations.

You 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 Execution.encodeURL(String)). So you can specify an absolute or relative path. 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 footprint at the server (since it is a component).

Limitation: Ignored by Inclusion

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 with <include>, <apply>, or servlets API. Also, they are ignored if the page is a zhtml file.




Last Update : 2023/12/21

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.