Browser Extras

docs

The CNET libraries have extended the MooTools Browser Hash to include some extra methods that help you manage window properties.

.getHost

Returns the fully qualified domain of the page. Will also return the host of a url passed to it.

Browser.getHost();
//returns "www.clientcide.com"
execute this code
Browser.getHost('http://www.example.com/some/path.html');
//returns "www.example.com"
execute this code

.getQueryStringValue

Returns the value of a query string key if it's defined. There shouldn't be one defined looking at this page, so for the purposes of this example, click this link before you execute the code below (it'll reload the page with a query string): reload with a query string

Browser.getQueryStringValue('red');
//returns: apple
execute this code

You can pass in an optional second argument; a different url. This will return the query string value in that instead of the window location.

Browser.getQueryStringValue('this', 'http://www.example.com?this=that');
//returns: that
execute this code

.getQueryStringValues

This returns an object of all the query string values. It takes an optional url as its argument, but defaults to the window location. If you haven't already, reload with a query string

Browser.getQueryStringValues();
//returns {red: 'apple',yellow:'lemon',green:'lime'}
execute this code
Browser.getQueryStringValues('http://www.example.com?this=that');
//returns {this:'that'}
execute this code

.qs

Browser.qs is kind of a shortcut to Browser.getQueryStringValues() except that .qs is not a function it's the object itself. You can't pass a url to it, so it represents only the values in the window location.

Browser.qs;
//returns {red: 'apple',yellow:'lemon',green:'lime'}
execute this code

.getPort

Returns the port of the url as a string, if there is one.

Browser.getPort();
//returns: false
execute this code
Browser.getPort('http://www.example.com:8001/something.html');
//returns: 8001 (a string)
execute this code

cnet-libraries/02-browser/00-browser.extras.txt · Last modified: 2008/11/17 23:25 by aaron-n