开发者

how to get innerHtml of body without an iframe with jquery

I have page with html something like this

<body><iframe ></iframe><div id="menu">......</div>.....</body>

I wa开发者_高级运维nt to get the innerHTML of the body but without the iframe? How can i do that in jquery?


Try with .clone:

$(document.body)
    .clone()
    .find('iframe')
        .remove()
    .end()
    .html();


$(document).ready(function(){
    $('body').not('iframe').html();
});

that should get everything in the body but the iframe. you'll probably want to store that in a variable or something for reference later


I have found another way to do it

var page = $('body').html();
page = $('<div>' + page + '</div>');
var html = $(page).find('iframe').remove().end().html();

html variable contains the html without the iframe.

And it works with IE, since jquery.clone() did not work on my page may be because of malformed html as @lonesomeday suggestted

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜