jquery - Chrome-extension Javascript to detect dynamically-loaded content -
i'm implementing chrome extension app. i want replace href attribute in tag (on webapp's homepage) "#". problem tag might dynamically loaded ajax, , reloaded user actions. suggestions on how let chrome-extension detect ajax loaded html content?
there 2 ways it,
first solution handling ajax requests
there .ajaxcomplete() function in jquery handles ajax request on page.
in content script,
var actualcode = '(' + function() { $(document).ajaxcomplete(function() { alert('content has been changed, should change href tag again'); // chaging href tag code here }); } + ')();'; var script = document.createelement('script'); script.textcontent = actualcode; (document.head||document.documentelement).appendchild(script); script.parentnode.removechild(script); second solution listening content changes
this possible mutation events, again in content script
$(document).bind("domsubtreemodified", function() { alert("something has been changed on page, should update href tag"); }); you might use different selector restrict elements you're controling changes.
$("body").bind("domsubtreemodified", function() {}); // listen changes on body content $("#mydiv").bind("domsubtreemodified", function() {}); // listen changes on #mydiv content
Comments
Post a Comment