cant use javascript from included ajax page xmlhttp -


got little ajax happening using xmlhttprequest, replaces div , works intended.

but cant seem included ajax page run javascript. how can run javascript included ajax page?

ie: mainpage.php has select form, on select change event includepage.php gets loaded div on page , changes based on selected in select box, works fine , intended using xmlhttp, issue im having trying run javascript included page, ie: simple alertbox.

there no code past, , maybe standard behaviour acnt find infomation on on how run javascript within included ajax page replaces div appreciated.

when insert scripts in content via innerhtml, scripts don't run browser.

if want them run, need find scripts in content, text them , insert them new scripts inserted document. long scripts don't need run in place using document.write(), work fine , libraries jquery automatically when inserting html document.

here's basic demo how works: http://jsfiddle.net/jfriend00/2trqw/

// insert dynamic content has script in // simulate what's happening ajax call var s = 'hello<s' + 'cript>alert("hello");  document.getelementbyid("result").style.color = "red";</s' + 'cript>'; var obj = document.getelementbyid("result"); obj.innerhtml = s;  // find script tags in dynamic content var scripts = obj.getelementsbytagname("script");  // create new script tags can copy script content on // , insert new script tags document make browser // run scripts var head = document.getelementsbytagname("head")[0]; (var = 0; < scripts.length; i++) {     var oldscript = scripts[i].parentnode.removechild(scripts[i]);     var newscript = document.createelement("script");     newscript.type = "text/javascript";     newscript.textcontent = oldscript.textcontent;     head.appendchild(newscript); } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -