Location class

From PhiWiki
Jump to: navigation, search

The Location class offers the usual functions and properties for the current set URL of the document. The location is a sub class of the Window class. In other browsers you have write access to all properties. However in Phi only window.location.href is writeable.


In Phi you have to specify the complete specifier including the window parent class, location without window will not work.

var l=window.location;


  • String hash [read]
  • String host [read]
  • String hostname [read]
  • String href [read|write]
  • String pathname [read]
  • String port [read]
  • String protocol [read]
  • String search [read]

String hash

Returns the anchor of the URL.

// url=http://www.phisys.com/index.phis?philang=fr#myanchor
var anchor=window.location.hash; // anchor=#myanchor

Note: Phi does not provide the concept of anchors in a document, because the complete layout is position based. However you can specify anchors in a Layouted Rich Text element to create jump points in larger contents.

String host

Stores the full server name including an optional port number.

String hostname

Stores the full server name excluding an optional port number.

String href

Stores the full URI of the document. Setting this property opens a new document.

See also: phi.href.

String pathname

Returns the pathname of the current URI.

var p=window.location.pathname // URI: https://www.phisys.com/services/login.phis
// p=/services/login.phis

String port

Returns the used port number or an empty string if no port is set (usually if the standard port '80' is used).

var p=window.location.port;

String protocol

Returns the current used protocol (mostly: http://).

String search

Contains the query item string (the string after the '?').

var s=window.location.search; // URI: http://www.phisys.com?philang=fr
// s='?philang=fr'


Void reload()

Reloads the current page. This has the same effect as the user presses the reload button of the browser.


Additional notes

The standard function window.location.replace() is currently not provided in Phi!