Techniques and tips for creating scripts
Position of scripts
It is standard
practice to put client-side scripts in the Head section of your document,
but the Page view in the HTML editor does not handle scripts in
the Head section.
You can put client-side scripts in the Body section, but:
- Scripts are not allowed within a TEXTAREA or SELECT
tag - There are restrictions for server scripts
that build client scripts
Balanced HTML that the editor can understand
Page view in
the HTML editor requires valid HTML, so if you use a script to build
part of an element and use straight HTML for the rest of the element,
the editor will have trouble displaying the page containing the
element in Page view. If you want to use Page view, make sure the
HTML on your page is balanced. Start and finish an element in HTML
only or in a script only. Do not start in one mode and finish in
the other.
For example, if a script is to provide data for a table, you
might think it would be easiest to code the table’s heading
row in HTML and then include a script for the data. To take advantage
of the editor, however, it would be better to create the heading
row in the script too, even if it seems like more work. When you
save a page containing unbalanced client- and server-side
script, the editor might alter part of the script that displays
in the integrated Script editor.
URLs in scripts
A Web target manages links in
HTML pages and JSPs. It remaps the URLs according to the directory
structure of the target or deployed site. However, a Web target
cannot manage URLs in scripts the way it manages URLs in HTML attributes.
Therefore, when you build URLs dynamically in a script, use methods
provided in the Web Target object model to get information about
the server and directory structure so that the URLs reflect the
current environment.
The following methods belong to psDocumentClass and can be
used to build a URL dynamically:
- File
- FileExtension
- Path
- Site
Example
To build a URL, your script might include code like this:
|
1 |
"http://" + psDocument.Site() + "/" + filefortoday + ".htm"; |