javascript - Using JQuery to delay loading of div, code not working in Chrome (window.onload) -


i'm using code below delay loading of div until entire web page loaded. works in firefox , safari (because each have lines in code make sure works each, haven't tested ie yet), not in chrome (which should, think, work window.onload).

could please me out this?

<script type="text/javascript">  function insertfb(){     var html='<div class="fb-page" data-href="https://www.facebook.com/bobcaputolivingwell" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true" data-show-posts="true"><div class="fb-xfbml-parse-ignore"><blockquote cite="https://www.facebook.com/bobcaputolivingwell"><a href="https://www.facebook.com/bobcaputolivingwell">bob caputo living well</a></blockquote></div></div>';     $("#fb_page").html(html); }  if (document.addeventlistener){     document.addeventlistener("domcontentloaded", insertfb, false); }  if (/webkit/i.test(navigator.useragent)){     var _timer = setinterval(function(){         if(/loaded|complete/.test(document.readystate)){             insertfb();         }     },10); }  window.onload = insertfb(); </script> 

well, firstly i'll answer question:

it's not working in google chrome, because you're using setinterval, , javascript case-sensitive language. correct name of method setinterval.


besides that, code full of errors, check method inside document, , don't use else if check others, check all, , call method want 2 or more times.

the other thing you're using setinterval you're never clearing interval, thing gonna run every 10ms forever.

and finally, last thing, you're calling insertfb function when you're trying attach onload event. shouldn't using parenthesis that.


take @ can use addeventlistener? , @ can use domcontentloaded?, , you'll see it's supported major browsers, old ones, , should use way, if need support ie8 (nowadays it's unlikely).


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -