Javascript 使用jquery将iframe转换为字符串

Javascript 使用jquery将iframe转换为字符串,javascript,php,jquery,iframe,Javascript,Php,Jquery,Iframe,我需要将iframe转换为字符串变量,然后使用php发送到服务器: <center><iframe id="probando" src="prueba2.html" scrolling="auto" height="700" width="800" marginheight="0" marginwidth="0" name="probando"></iframe></center> 我不知道怎样才能继续 请帮帮我

我需要将iframe转换为字符串变量,然后使用php发送到服务器:

<center><iframe id="probando" src="prueba2.html" scrolling="auto" height="700"                width="800" marginheight="0" marginwidth="0" name="probando"></iframe></center>

我不知道怎样才能继续

请帮帮我。谢谢

使用

var html = document.getElementById("probando").outerHTML;

或者你可以使用

var string = $('#probando').closest('center').html();

这个答案是使用jQuery获取iframe内部的内容。请注意,这将在您自己的域中正常工作:

$(function(){
    $('#probando').on('load', function(){
        var str = $(this).contents().find('html').prop('outerHTML');
        console.log(str);
    });
});

您需要将该iframe转换为字符串。。。或者您正在寻找iframe内容?这个问题可以用几种方式来解释。请多花点精力解释你的全部问题。如果您想要的只是标签。。这是一件事,如果您想要内容,它完全不同于我可以在字符串变量adn中插入iframe内容,然后用php发送到服务器。@Lewis88您的解释没有解释太多。我会理解您希望将代码加载到iframe中,而不是iframe代码本身。怎么说页面中没有其他
center
标记?只会得到第一个,可能不是正确的。@charlietfl在OP中有一个
中心
标记。@erkaner如果页面中有一个
,你可以确定很有可能还有其他的。.如果框架上甚至有一个id,它与我们在OP中看到的代码部分一起工作,但是好的做法是得到真正的目标元素@charlietfl,这是一个解决问题的答案,这一切都很重要。非常感谢,这就是我需要的!
$(function(){
    $('#probando').on('load', function(){
        var str = $(this).contents().find('html').prop('outerHTML');
        console.log(str);
    });
});