ajax成功中的广告调用响应包含document.write

时间:2013-07-19 11:03:28

标签: javascript ajax document.write

我们目前希望在更多的ajax加载后加载广告。但该广告调用响应包含document.write,并在调用后重定向到广告本身。没有方法只能获取广告html并附加它。所以我们必须在ajax成功中处理document.write。我看到了一些关于iframe的内容,但我真的不知道应该如何实现它。

$.ajax({
     .
     . 
     .

    success: function( response ) {
        var loadedAd = ad call here; -- but it redirects to the ad itself due to the document.write in ad response.

感谢。

1 个答案:

答案 0 :(得分:0)

从iframe上下文发送ajax请求应该可以解决问题,或者至少可以解析广告结果代码以使用DOM相关函数替换document.write调用。

使用iframe上下文评估ajax响应的示例:

var adCode = "document.write('example')",
    iframe = document.getElementById('myFrame');

iframe.contentWindow.eval(adCode);
相关问题