Document class

From PhiWiki
Jump to: navigation, search

Describes the base settings for a web or intranet document. You can change ie. the title, author, company, copyright, etc. of the page. It is even possible to set the JavaScript (in the server environment) for the requesting client. However most settings are useful in the server environment only.


The Document class has many additional functions in the Phi environment which are not available in HTML so they will be ignored outside Phi and are mainly intended for the server scripting environment. Those functions are marked with the 'Phi' symbol.

Note: in many browsers document is accessible as a global object. This is also true for Phi clients since v1.3.0. Before you had to reference it with window.document! In the server environment document is a global object with full access to all additional Phi functions.

var d=document; // server
var d=window.document; // client before v1.3.0
var d=document; // client since v1.3.0

In the function examples the server environment is marked with '// server' and the client (browser) environment with '// client'.

Note: in the client scripting environment all properties are read only (except title).

Probably you will make rarely use of the Document class in the client scripting environment, usually all settings are done already by the server and can not be changed after!


  • String action [read|write] Phi
  • String author [read|write] Phi
  • String bgColor [read|write]
  • String company [read|write] Phi
  • String copyright [read|write] Phi
  • String fontFamily [read|write] Phi
  • Number height [read|write] Phi
  • String id [read] Phi
  • Number itemCount [read] Phi
  • StringArray itemIds [read] Phi
  • String javascript [read|write] Phi
  • String keys [read|write] Phi
  • String lang [read|write] Phi
  • StringArray languages [read] Phi
  • String openGraph [read|write] Phi v1.3.0
  • StringArray properties [read] Phi
  • String session [read|write] Phi
  • String sessionRedirect [read|write] Phi
  • String styleSheet [read|write] Phi
  • String templatePage [read|write] Phi
  • String title [read|write]
  • String version [read|write] Phi
  • Number width [read|write] Phi

All properties can be set and read (replace <prop_name> with one of the above property names) with:

var value=document.<prop_name>; // server [read]
var value=window.document.<prop_name>; // client [read] before v1.3.0
var value=document.<prop_name>; // client [read] since v1.3.0
document.<prop_name>=value; // server [write]
window.document.<prop_name>=value; // client [write]
document.<prop_name>=value; // client [write] since v1.3.0

String action

URL to the document where the forms will be processed.

Warning: this has no effect in the client (browser) environment. Use window.document.phiform.action instead.

String author

Author of the document.

String bgColor

Background color of the document.

String company

Company name.

String copyright

Copyright for the document.

String fontFamily

Default font family.

Number height

Height of the document in px.

String id

Document id (page name).

Number itemCount

Count of all items in the document.

StringArray itemIds

List of all item ids.

var i=0;
while ( document.itemIds[i] ) print( document.itemIds[i++] );

String javascript

contains the defined JavaScript which will be send to the browser.

String keywords

Content keywords (meta data) for this document.

String lang

Current set language for this document. In the client environment use phi.lang instead.

StringArray languages

Available languages for this document.

var i=0;
while ( document.languages[i] ) print( document.languages[i++] ); // server
while ( window.document.languages[i] ) doSomething( window.document.languages[i++] ); // client

String openGraph

Sets or returns the open graph properties of the page (usually used with Facebook). Use the newline character '\n' as a line separator. Key/value pairs are separated by '='.

document.openGraph='fb:app_id=123456789\nog:title=page title\nog:site_name=the \\"coolest\\" site available';

Warning: You have to escape quotation marks in the string with '\\' or the result is unpredictable (parsing would take too much time).

See also: Page settings.

StringArray properties

Properties list.

var int=0;
while ([i] ) print([i++] );

String session

Session key for the current user. In the client (browser) environment use phi.session instead.

var sid=window.document.session; // client (avoid this - does not work in HTML mode)
var sid=phi.session; // client (precedence - works in Phi mode and HTML)
var sid=document.session; // server

See also: Session management.

String sessionRedirect

Redirection to file name if the session is invalid.


The path has to be a file name relative (an URL is not working) to the document root and must start with a slash '/'. POST and GET variables from the current page are passed through.

Warning: this has no effect in the client (browser) environment.

String styleSheet

CSS for this document.

String templatePage

Master templage page to be loaded in the background.


String title

Document title.

document.title='My page title';

String version

Version number of this document.

Number width

Width of the document in px.



Item createElementById()

v1.0.1 Creates dynamically a new item with the Φ WID wid, name id, position left and top, size width and height. Default values are used for width and height if they are set to 0.

var item=document.createElementById( wid, id, left, top, width=0, height=0 );
var item=document.createElementById( 13, 'myellipse', 100, 200, 300, 300 ); // creates an ellipse (wid=13)

After creating an element you have normal access to its style, effect, etc. properties:

var ellipse=document.createElementById( 13, 'myellipse', 100, 100, 400, 400 );'#3389AF';

You find the special Φ WID for each element in the Element description.

Warning: this function is only available in the server environment!

Item getElementById()

Returns the item for the provided id or undefined if no such item with id is found.

var item=document.getElmentById( 'id' ); // server
var item=window.document.getElementById( 'id' ); // client (avoid this)
var item=phi.getElementById( 'id' ); // client (precedence in client scripting)

See also: phi.getElementById(), Item class.

Void removeElementById()

v1.0.1 Removes the element with id from the document.

document.removeElementById( id );
document.removeElementById( 'myellipse' );

Warning: this function is only available in the server environment!

Additional notes

Other functions are currently not supported by Phi since they are rarly used. Please let us know if you really need specific functions and we will consider to implement them in future releases.