最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get entire content of page? - Stack Overflow

programmeradmin2浏览0评论

So is it possible to snag the entire content of a page in its current state. For example, if interacting with a page, via jquery, I've modified the document by either inserting content, or by adding or removing class names. Is it possible to get the markup of this document in its current form from starting html tag to html tag?

So is it possible to snag the entire content of a page in its current state. For example, if interacting with a page, via jquery, I've modified the document by either inserting content, or by adding or removing class names. Is it possible to get the markup of this document in its current form from starting html tag to html tag?

Share Improve this question asked May 14, 2009 at 22:00 DavidDavid 19.7k13 gold badges67 silver badges88 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 8

Something like

document.documentElement.innerHTML

This doesn't include the <html> opening and closing tags

Can't you just get the root object in the DOM and call innerHTML to get it all?

just call $('html').html() using jquery to get page source.

<html>
<head>
    <title>Just a test</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {
            $('#showContent').click(function(event){
                event.preventDefault();
                var pageSource = '<html>' + $('html').html() +'</html>';
                alert(pageSource);
            });
    });
    </script>
</head>
<body>
    <a href="#" id="showContent" >show content</a>
</body>
</html>
发布评论

评论列表(0)

  1. 暂无评论