kango.browser

Summary

Name Description
addEventListener Registers an event handler for the specified event type
removeEventListener Removes an event handler that the addEventListener method registered
getName Returns browser name

Methods

addEventListener

kango.browser.addEventListener(name, callback)

Registers an event handler for the specified event type.

Arguments:
  • name (string) – event name
  • callback (function(event)) – callback function

Events list:

DOCUMENT_COMPLETE // Fired when document is fully loaded (after DOMContentLoaded page event)
event = {
    KangoBrowserTab target,
    string url,
    string title
}

BEFORE_NAVIGATE   // Fired when request starts
event = {
    KangoBrowserTab target,
    string url
}

TAB_CREATED       // Fired when new tab created
event = {
    string tabId,
    KangoBrowserTab target
}

TAB_CHANGED       // Fired when tab changed
event = {
    string tabId,
    KangoBrowserTab target,
    string url,
    string title
}

TAB_REMOVED       // Fired when tab removed
event = {
    string tabId
}

Note

To access tab DOM you should use content scripts.

Example:

kango.browser.addEventListener(kango.browser.event.TAB_CHANGED, function(event) {
    // event = {string tabId, KangoBrowserTab target, string url, string title};
    kango.console.log('Tab was changed to ' + event.url);
});

See also

KangoBrowserTab

removeEventListener

kango.browser.removeEventListener(name, callback)

Removes an event handler that the kango.browser.addEventListener() method registered.

Arguments:
  • name (string) – event name
  • callback (function(event)) – callback function

Example:

// event handler
var onBeforeNavigate = function(event) {
    kango.console.log('BeforeNavigate url=' + event.url);
};

// add event handler
kango.browser.addEventListener(kango.browser.event.BEFORE_NAVIGATE, onBeforeNavigate);

// remove event handler
kango.browser.removeEventListener(kango.browser.event.BEFORE_NAVIGATE, onBeforeNavigate);

getName

kango.browser.getName()

Returns browser name. Can be used in content scripts.

Returns:browser name
Return type:string

Possible values:

browserNames = [
    'firefox',
    'chrome',
    'safari',
    'ie'
]

Example:

// outputs current browser name to console
var browserName = kango.browser.getName();
kango.console.log(browserName);