Window.executeJavaScript on page *reload*?

Hi!
I found that
Window
supports such a very nice feature as
executeJavaScript(‘…’)
. Very cool to init something etc on a document load. Well, it works, as long as an event fired (e.g. user clicks something) or at init first time. But when user reloads a web-browser, of course, init() no more called and things that should be loaded on document load — skipped. So the only way I found so far is to trigger
getWindow()
which I override and executing JavaScript there.

But the problem is, that
getWindow(…)
is called exactly as twice per each reload. That is, if I output something to the canvas, it gets there twice. :frowning: I thought I can workaround that with a random ID’s and find dupes. Unlikely, it won’t work, because getWindow(…) will trigger freshly new call to the JavaScript.

Hence, mea culpa, is there a proper way to execute some javascript on document load once?

P.S. Everything is happening as Portlet 2.0 on Liferay. :slight_smile:

Aww, interesting problem. Reloading was considered in the design of the method (see
#3589
), but from a bit different perspective as it was assumed that any injected JavaScript is executed only once.

I think you can do it in the old-fashioned way by putting the JavaScript in a element inside a Label in Label.CONTENT_XHTML mode. I’m not totally sure if it works in all browsers though (such as IE6).

IMO, not very good idea, since session persists for 30 minutes and user fingers tends to press F5 to reload browser… :slight_smile:

Well, that’s what I was doing so far and that’s what makes me upset, since it makes totally unusable all this idea with executing JavaScript from Window API. :frowning:

IE6 not really a problem, since we have
a very nice patch
for it, LOL.