开发者

How to modify the html output of a dynamically loaded script in javascript?

I'm trying to take the output from the wordpress widget for Intense Debate and modify the html output that's returned. Though it's wordpress, all the widget is doing is returning a script tag. From what I've seen of how dynamically generated html works through a script tag, like

<script type='text/javascript' src='http://www.intensedebate.com/widgets/acctComment/12345/5'></script>

theirs is nothing special. It does this to call itself:

    for(var i=0; i<scripts.length; i++)
{
    if(scripts[i].src.indexOf('intensedebate.com/widgets/acctComment')>0)
    {
        if(scripts[i].defer)
        {
            if (window.addEventListener) 
            { 
                window.addEventListener("load", initIDWidget2, false); 
            } 
            else if (window.attachEvent) 
            {
                window.attachEvent('onload', initIDWidget2);
            }
        }
        else
        {
            document.write('<!--OMITTING HUGE HTML/JAVASCRIPT BLOCK-->');
            if ( typeof id_re开发者_JS百科cent_comments_loaded == 'function' )
                id_recent_comments_loaded();
        }
        break;
    }
}

And also passes in the html it inserts in a variable. It does

parentObj.insertBefore(theDiv,theObj);

to insert the html (theDiv being the final html, theObj being the script tag.) I can totally understand the flow of how it works. What's stumping me is how I can change it after it does it's onload, or how to change the output before it displays. I'm not sure the variables would be addressable as it does it's onLoad. Any advice? I'm not seeing this exact issue on StackOverflow, so I had to ask.

Thanks!


This can be done using livequery (http://docs.jquery.com/Plugins/livequery) by listening to child elements being created in a parent element.

<div id="foo"></div>

$("#foo p").livequery(function() {
   console.log("added something"); 
});

$(function() {
   $("#foo").append($("<p>lol</p>"));
});

fiddle

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜