Using variables in the popup-window's dimmensions

Forums » Dev.Opera » Opera Extensions Development Discussions

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

26. February 2012, 02:29:25

Using variables in the popup-window's dimmensions

Seems like its not working,



I would like to give users options for the dimensions because the size of the content varies, depending on other settings.
Seems I cant do that.

Also not defining the size should be on some automatic mode which would try to avoid using scrollbars at all cost or then whole extension looks terrible.


/Edit

with switch and case I am able to choose from several sizes for the popup window
and with some additional css like max-width and overflow:hidden I am able to control rest of the content it seems.

26. February 2012, 18:13:35

spadija

Posts: 1635

Using variables will work so long as those variables are defined. You could use something like this to set a default size:
var popupWidth = parseInt(localStorage['popupWidth'] || 100);
var popupHeight = parseInt(localStorage['popupHeight'] || 100);

27. February 2012, 22:19:02

Thank you, didn't realize that it was string... and thanks for || 100, would be ugly if I would forgot about clean installation.

28. February 2012, 07:56:02

d4n3

Posts: 957

That's the thing about localStorage (and other DOM Storage objects).

Everything that goes into it, is first put through JSON.stringify.
And using array access really translates to localStorage.setItem(key, value).

So you should be really using JSON.parse for values you get from it.

29. February 2012, 02:16:03

spadija

Posts: 1635

True, but if you're just storing numbers, parseInt will do the trick. If you use JSON.parse, make sure you test for the existence of the value first (or use the || trick) as JSON.parse(undefined) gets you an exception instead of a value.

Forums » Dev.Opera » Opera Extensions Development Discussions