Window class

From PhiWiki
Jump to: navigation, search

Describes the settings for a browser window. You can set timers and intervals or display message boxes. This class is available in the client environment only.

Usage

The Window class in Phi does currently not provide all standard functions HTML provides. The Window class is the parent class of the Document class.

var w=window;

Warning: do not use functions which are not listed here or they will probably not work in the Phi environment.

Since v1.3.0 the Window class is now also globally available in the Phi mode and member functions do not need to be prefixed with window.

alert(); // will work since v1.3.0
window.alert(); // will work
phi.alert(); // deprecated

Properties

The Window class does currently not provide any properties.

Functions

Void alert()

Opens a message box with string as text.

window.alert( string );

Note: Since v1.3.0 you can use the short hand alert().

Void back()

Requests a back action. This is the same as the user clicks on the browser's back button.

window.back();

Note: in Phi this will be silently ignored. See also: Additional notes.

Void clearInterval()

Clears the interval timer with ID id.

window.clearInterval( id );
clearInterval( id ); // v1.3.0

See also: window.setInterval().

Void clearTimeout()

Clears the single shot with ID id.

window.clearTimeout( id );

See also: window.setTimeout().

Void close()

Emits a signal to close the current window. It is up to the client if the browser accepts this and reacts appropriate.

window.close();

Boolean confirm()

Opens a message box presenting text to the user with a Yes and No button. Returns true if the Yes button is pressed or false otherwise.

var answer=window.confirm( 'text' );
if ( window.confirm( 'Should I continue with a smile?' ) ) { //smiling }

Void forward()

Requests a forward action. This is the same as the user clicks on the browser's forward tool button.

window.forward();

Note: in Phi this will be silently ignored. See also: Additional notes.

Void home()

Requests a home action. This is the same as the user clicks on the browser's home tool button.

window.home();

Note: in Phi this will be silently ignored. See also: Additional notes.

Void open()

Opens a new window. The url may be a relative file in the current directory or a complete URL.

window.open( url, target, options="" );
window.open( 'mydoc.phis', '_blank', 'width=400,height=600,status=no,menubar=no' );
window.open( 'http://www.phisys.com', '_self' );

Session and language are not automatically added: if you want to pass the philang and phisid (session) use:

window.open( 'mydoc.phis?phisid='+phi.session+'&philang='+phi.lang, 'mydoc_id', 'width=600,hight=400' );

The target attribute can be one of:

  • _self - the new page will be opened in the same window
  • _blank - a new window will be opened
  • named_id - a named id - same ids are opened in the same appropriate window

The options attribute can be one of the following keywords (separated by a colon):

  • width - the window width [px]
  • height - the window height [px]
  • top - the window y-position of the screen [px]
  • left - the window x-position of the screen [px]
  • location - show location bar [yes|no], default: no
  • menubar - show a menu [yes|no], default: no
  • status - show the status bar [yes|no], default: no
  • toolbar - show a tool bar [yes|no], default: no
  • scrollbars - show scrollbars [yes|no], default: automatically set

Warning: not all browsers support all options as listed above. Phi ignores some options if target is _self and the window is opened in Amphibia directly and not in a separate window.

Note: you should open a *.phis document only with window.open. The reason why is Phi starts the PhiApp which currently only supports an application/x-phi stream. Otherwise Phi will ask you for downloading the file instead of rendering appropriate HTML.

Void print()

Opens a printer dialog and prints the current document.

String prompt()

Opens a dialog with the description text, an input field (with default value) and an Ok and Abort button.

var value=window.prompt( text, value );
var value=window.prompt( 'Please enter a size', '100' );
if ( value=='100' ) doSomething();

Void resizeBy()

Resizes the window by dx and dy pixels. Negative values will shrink the window.

window.resizeBy( dx, dy );
window.resizeBy( -10, 10 ); // shrinks the window in width and adds 10 pixels to height.

Note: Some browser silently ignore this, if the window is part of a tabed group of windows.

Void resizeTo()

Resizes the windwow to width and height pixels.

window.resizeTo( width, height );
window.resizeTo( 400, 200 );

Note: Some browser silently ignore this, if the window is part of a tabed group of windows.

Number setInterval()

Sets an interval timer shooting every time ms by calling function func.

var id=window.setInterval( func, time );
var id=window.setInterval( function(){ dosomething(); }, 5000 );
var id=window.setInterval( 'myfunc()', 200 ); // calls the global function myfunc() every 200 ms.

Since v1.3.0 setInterval is not limited anymore to invoke global functions.

window.setInterval( 'myfunc()', 200 );
function myfunc() { 
  doSomething();
};
function myfunc() {
  this.subfunc=function() {
    doSomething();
  };
  setInterval( subfunc, 200 );
};

Number setTimeout()

Sets a single shot timer shooting after time ms by calling function func.

var id=window.setTimeout( 'func', time );
var id=window.setTimeout( function(){ doSomething(); }, 5000 ); // executes doSomething() after 5s
var id=window.setTimeout( 'myfunc()', 200 ); // calls the global function myfunc() after 200 ms.

Since v1.3.0 setTimeout() is not limited anymore to invoke global functions.

window.setTimeout( 'myfunc()', 200 );
function myfunc() { 
  doSomething();
};
function myfunc() {
  this.subfunc=function() {
    doSomething();
  }
  setTimeout( subfunc, 200 );
};

Additional notes

Other functions are currently not supported by Phi. More functions will be available in future releases.

Phi does not support the concept of back(), forward() and home() actions. The main focus is in developing internet and intranet applications so it is the responsibility of the developer if he/she wants to provide buttons for such actions to the user.