如何将带有javascript的IFRAME添加到ajax加载的内容中

时间:2010-12-07 11:00:58

标签: javascript ajax iframe dynamic

如何将带有javascript的IFRAME添加到ajax刷新内容?假设我有这样的事情:

$('#bar').delegate('.scroll-content-item span a', 'click', function() {
    var object_id = $(this).parent().attr("class");
    $.ajax({
        type: "POST",
        url: "/myfunction.php",
        data: "action=object_id=" + object_id,
        dataType: "json",
        success: function(data){
            $('.info').html(data['html']);                
        }
    });
    return false;
});

所以我尝试在成功时添加此代码:

            document.write('<IFRAME vspace=0 height=71 style="padding:10px" marginHeight=5 src="" frameBorder=0 width=54 name="pliggit" scrolling=no><script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script><script type="text/javascript">stLight.options({publisher:"b24b6378-26a9-435c-ac5f-8aee4f59529c"});</script></IFRAME>');

但我得到了Unterminated string literal

2 个答案:

答案 0 :(得分:0)

现在还早,但是你试过引用你的属性吗?

或者您可以在javascript中创建iframe:

var iframe = document.createElement('iframe');
iframe.setAttribute('vspace', '0');

等..?

答案 1 :(得分:0)

它不喜欢</script>标记。我仍在寻找一个js答案来编码一段代码,以便Javascript不会barf。

相关问题