javascript - Displaying popup window if it is taking more than 3 seconds to load a page -


need display popup before page load if page loading more 3 seconds. used below code displays popup if page load less tahn 3 seocnds also. popup need displayed if page loading takes more time not less time.

<script type="text/javascript">     settimeout(fnshowpopup, 1000);     function fnshowpopup() {         var answer = confirm("it may take few time open docuemnt. click yes if want open docuemnt in native format or click on cancel continue viewing docuemnt")         if (answer)             window.open(nativeview())   } </script> 

settimeout(func, delay) comes method abort timer: cleartimeout(timeoutid)

<script> var mytimer = settimeout(fnshowpopup, 3000); if (typeof(window.addeventlistener) === 'function') {     // standard conforming browsers     window.addeventlistener('load', function () {         cleartimeout(mytimer);     }, true); } else {     // legacy, ie8 , less     window.attachevent('onload', function () {         cleartimeout(mytimer);     }); } </script> 

put in <head> of page, before other <script>s, <style>s or <link>s.

in fnshowpopup function may want stop page loading if user chooses "native format". see https://stackoverflow.com/a/10415265/


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -