jquery - Executing Javascript scripts after pasting HTML code -


i'm doing experiments, , found when execute code on web pages :

document.documentelement.innerhtml = document.documentelement.innerhtml; 

javascript scripts 'disabled'. here little script wrote re-execute scripts using jquery ( you'll need inject jquery on websites ( i'm using firebug + firequery )) :

// disabling javascript scripts document.documentelement.innerhtml = document.documentelement.innerhtml;  // saving scripts tags , parent var scripts = []; jquery('html').find('script').each(function(){     scripts.push([jquery(this),jquery(this).parent()]); }).remove(); // removing script tags  // re-appending deleted script tags in right place (var in scripts) {     scripts[i][1].append(scripts[i][0]); } 

so script works on of website tried, except 1 : google ( in firefox )

the thing i'm trying storing google html, , pasting iframe ( via firefox extension ). working except can't javascript scripts working ( no autocomplete, buttons not working... ). here errors :

gapi.loaded_0 not function

window.google.pmc undefined

i thinking that, may due execution order issue or something. how can fix that. there other way re-run javascript scripts ? or better way doing i'm doing ?

thank !

yes! there better way doing.

first, happening:

when use innerhtml existing elements removed dom. not quite in 'burn , salt earth' because other references might survive, off dom.

fortunately, there easy way deal this:

this wonderful discussion of event delegation describes need do. it's worth reading understand behind scenes.

once have that, @ jquery's event delgation bunch of work you:

since didn't show html, i'll invent some:

<div id="contents-will-be-replaced">   <button>click me</button> </div>   // attach div // listen buttons $( "#contents-will-be-replaced" ).on( "click", "button", function() {   alert("button pushed"); }); 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -