Save a popout’s position

The screen position of a caplin.popout.Popout is not automatically persisted between sessions. It does, however expose the geometric data required to do so. This enables implementation code to choose its own persistance strategy.


Here is a simple example of how to persist the position of a popout using local storage.

First of all we get the geometric data from the popout object, and persist it to local storage (this would generally be done on window.onunload):

var geometrics = popout.getWindowGeometrics();

localStorage.myPopoutGeometrics = JSON.stringify(geometrics);

Then we can update the code that launches our popout to use the persisted geometric data:

var geometrics = { left : 10, top : 10, width : 200, height : 100 };

if(localStorage.myPopoutGeometrics !== undefined) {
    geometrics = JSON.parse(localStorage.myPopoutGeometrics);

var popout = new caplin.popout.Popout('popout', geometrics);, geometrics.height);

A note on window positioning

All browsers position new windows relative to the top left of the OS’s main screen, but still have widely different behaviours in regards to positioning:

  • Firefox: Works as expected, even for negative positioning.

  • IE: Same as Firefox, except does not allow negative positioning. This means a popout cannot be placed above or to the left of the OS’s main screen.

  • Chrome: Can handle negative positioning like Firefox, but always places popouts on the same screen as the window that opened the popout. If a popout would be opened on another screen, it will instead appear at the edge of the screen containing the parent window.

See also: