Redirect [removed] from javascript script

前端 未结 4 1951
渐次进展
渐次进展 2021-02-11 05:37

We want to serve ads on our site but the adserver we are in talks with has issues with delivering their advertising fast enough for us.

The issue as I see it is that we

4条回答
  •  渐次进展
    2021-02-11 05:55

    If I understand correctly, you want to capture document.write to a variable instead of writing it to the document. You can actually do this:

    var advertHtml = '';
    var oldWrite = document.write;
    
    document.write = function(str)
    {
        advertHtml += str;
    }
    
    // Ad code here
    
    // Put back the old function
    document.write = oldWrite;
    
    // Later...
    ...innerHTML = advertHtml;
    

    You still have the hit of loading the script file though.

提交回复
热议问题