javascript - How to force a script reload and re-execute? -


i have page loading script third party (news feed). src url script assigned dynamically on load (per third party code).

<div id="div1287">     <!-- dynamically-generated elements go here. --> </div>  <script id="script0348710783" type="javascript/text"> </script>  <script type="javascript/text">     document.getelementbyid('script0348710783').src='http://onebighairyurl'; </script> 

the script loaded http://onebighairyurl creates , loads elements various stuff news feed, pretty formatting, etc. div1287 (the id "div1287" passed in http://onebighairyurl script knows load content).

the problem is, loads once. i'd reload (and display new content) every n seconds.

so, thought i'd try this:

<div id="div1287">     <!-- dynamically-generated elements go here. --> </div>  <script id="script0348710783" type="javascript/text"> </script>  <script type="javascript/text">     loaditup=function() {         alert('loading...');         var divelement = document.getelementbyid('div1287');         var screlement = document.getelementbyid('script0348710783');          divelement.innerhtml='';         screlement.innerhtml='';         screlement.src='';         screlement.src='http://onebighairyurl';         settimeout(loaditup, 10000);     };     loaditup(); </script> 

i alert, div clears, no dynamically-generated html reloaded it.

any idea i'm doing wrong?

how adding new script tag <head> script (re)load? below:

<script language="text/javascript">    function load_js()    {       var head= document.getelementsbytagname('head')[0];       var script= document.createelement('script');       script.type= 'text/javascript';       script.src= 'source_file.js';       head.appendchild(script);    }    load_js(); </script> 

the main point inserting new script tag -- can remove old 1 without consequence. may need add timestamp query string if have caching issues.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -