javascript - JQM: popup not closing on timeout? -
i have managed popup open on page load, first time page opened. once opens, want close on own after several seconds, not able that.
this code using:
<script type="text/javascript" language="javascript"> $(document).on('pageshow', function (event) { if (sessionstorage.popupshown != 'true') { $('#strelica').popup('open', {positionto: '#hitnizbor'}); sessionstorage.popupshown = 'true'; settimeout(function () { $("#strelica").popup("close"); }, 3000); } else{ alert('already shown popup'); } }); </script>
your example should work, made safer version: http://jsfiddle.net/gajotres/uauar/
$(document).on('pageshow', '#index', function(){ var start = settimeout(function () { $('#strelica').popup('open', {positionto: '#hitnizbor'}); clearinterval(start); }, 0); var stop = settimeout(function () { $("#strelica").popup("close"); clearinterval(stop); }, 3000); });
this code can used in every page event, not pageshow. if want executed once use pageinit.
clearinterval here prevent constant opening , closing. if have more questions feel free ask.
Comments
Post a Comment