Skip to content

JavaScript events and functions

Aerilius edited this page Apr 11, 2013 · 3 revisions

Events

window.onresize

Is triggered when the viewport's size changes.

In Internet Explorer, it is triggered twice.

document.onfocus

Is triggered when the html document gets focus. In Internet Explorer, you can also use document.onfocusin.

document.onblur

Is triggered when the html document looses focus.

In Internet Explorer, the document is also blurred when an element within the document gets focus (and removes focus from the document). For example, when a user clicks into an input in an unfocussed webdialog, it would trigger in Internet Explorer document.onfocus, document.onblur, input.onfocus, but in Safari only document.onfocus and input.onfocus. In Internet Explorer, use document.onfocusout instead.

Functions

window.focus()

This works in Safari, but not in Internet Explorer. Use WebDialog.bring_to_front which not only brings the dialog on top of the window stack, but additionally gives it focus (on Windows and OS X). Then use focus() on a specific input element.

window.close()

This works in Safari, but not in Internet Explorer. Use WebDialog.close in addition or instead.

##window.screenLeft, window.screenX; window.screenTop, window.screenY

In Internet Explorer, the window.screenLeft and window.screenTop return the position of the client area, ie. the distance of the top left corner of the webdialog content from the top left corner of the screen (the other two properties are not supported in IE<9).

In WebKit all these properties return the position of the window's top left corner (including window decorations).