SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    jquery clone() full page source

    I am trying to figure out how I can copy the full page source, I have been trying to do it with clone() but not everything is copied and I need to be able to create a full html source code clone from the doctype down to the closing html tag is this possible?

    I have tried clone('html') but that is null, if not possible is there any other way using javascript besides going to see the source and copying it?
    Do you get bothered because I do the same thing every day?
    Do you question why I do it?
    Then find something that you actually like doing!!!

    Stop thinking on what I do.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,197
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    JavaScript alone only allows you to clone the <body> contents, to clone your entire source you would need to server a server side language such as PHP.

  3. #3
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,115
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by chris.upjohn View Post
    JavaScript alone only allows you to clone the <body> contents, to clone your entire source you would need to server a server side language such as PHP.
    That's not true, you can certainly get elements from within the <head>.
    document.documentElement points to the <html> root element.

    One way to get the source is:
    Code javascript:
    document.documentElement.outerHTML
    Only tested in Firefox. You might need to do some inspecting.

  4. #4
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying this:
    $('textarea').text( $("html").clone().html() ) ;
    Code:
      
    <html>
    <head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
    // http://www.w3schools.com/jquery/html_clone.asp
    // http://api.jquery.com/contents/
    // http://www.sitepoint.com/forums/showthread.php?857518-jquery-clone%28%29-full-page-source
    
    $(document).ready(function(){
    
      $("button").click(function(){
    
    
    /*
    var n = $("html").contents(); 
    alert(n.length); // 3
    for(var i =0; i< n.length; i++) {
    alert( $(n[i]).html()); 
    //alert( $(n[i]).parent().html()); 
    }
    */
    
    //alert(  $("html").clone().html() );
    //$('div').text( $("html").clone().html() ) ;
    
    //alert(  $("html").clone().text() );
    // $('div').text( $("html").clone().text() ) ;
    
    //$('textarea').text( $("html").clone().text() ) ;
    
    $('textarea').text( $("html").clone().html() ) ;
    
      });
    });
    
    </script>
    </head>
    <body>
    <button>Clicm me</button>
    <div></div>
    <textarea rows="10" cols="50"></textarea>
    </body>
    </html>
    Bismillahirrahmanirrahîm
    Bizi doğru yola, kendilerine nimet verdiklerinin yoluna ilet; gazaba uğrayanların ve sapıklarınkine değil.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •