I try to execute a JS snippet only once, after the page is fully loaded, and JQM has taken care of all the ui modifications (i.e. lists, buttons, etc.). I want it to be executed only on this page, and not on subsequent pages.
What I tried first was
<script> $('[data-role=page]').live("pageshow", function() { alert("Ready!"); }); </script>
This is because the function is now bound to the page div and is executed every time any subsequent page is displayed. However, I want this to be done only once and only for the page containing this JS snippet.
Is there any way to listen to the showhow event, without binding functions to it.
The only way I was able to do this was to snap and unlock as follows:
<script> $('[data-role=page]').bind("pageshow.test", testfun); function testfun() { alert("Ready!"); $('[data-role=page]').unbind("pageshow.test", testfun); } </script>
But is there a more elegant way to do this?
Steve source share