开发者

resizeTo in JS gives me "Access is denied" error, how to know if browser is ready?

I have a web app, whose UI is written in GWT, where for various reasons I need to resize the active window when the server reports things. To do this I use a JSNI function which uses resizeTo and everything works great. I did a small test and tried sending a few updates from the server and got an "Access is denied" error from the resizeTo command. After googling a bit I discovered that this is because the browser is still busy with another resizeTo command and throws an exception due to that. My question is if anyone has a good way to see if the browser is ready/available to be resized? A current workaround I'm thinking, but I don't particularly like, is having a try { } catch() block and if an exception is thrown then catch it and call the function again in timeout but I would like to have a more straightforward way.

Thanks, Ittai

EDIT: I thought of another problem though, what if update A and update B return together from the server and A starts while B sleeps for X ms, in the mean time update C is sent from the server and finds that A is finished although B hasn't awaken yet so C executes and only then B which is wrong because B does not contain the most recent size. Do you h开发者_运维问答ave an idea for a solution? Is that a race condition problem? Thanks


Ittai,

If I were a lazy man (and I am) I would use jQuery's resize() because it gives you a callback:

http://docs.jquery.com/Events/resize

You can do something like

ready = false;
$(window).resize(function(){
    ready = true;
});

Noah

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜