Executing [removed] elements inserted with [removed]

后端 未结 20 2525
囚心锁ツ
囚心锁ツ 2020-11-22 00:12

I\'ve got a script that inserts some content into an element using innerHTML.

The content could for example be:



        
20条回答
  •  无人及你
    2020-11-22 00:57

    It's easier to use jquery $(parent).html(code) instead of parent.innerHTML = code:

    var oldDocumentWrite = document.write;
    var oldDocumentWriteln = document.writeln;
    try {
        document.write = function(code) {
            $(parent).append(code);
        }
        document.writeln = function(code) {
            document.write(code + "
    "); } $(parent).html(html); } finally { $(window).load(function() { document.write = oldDocumentWrite document.writeln = oldDocumentWriteln }) }

    This also works with scripts that use document.write and scripts loaded via src attribute. Unfortunately even this doesn't work with Google AdSense scripts.

提交回复
热议问题