Get HTML source code as a string

前端 未结 5 1417
悲&欢浪女
悲&欢浪女 2021-02-07 19:25

I want the source code of an HTML page (1.html) to be used in another page (2.html). Furthermore, I want to perform operations on it in 2.html

相关标签:
5条回答
  • 2021-02-07 19:35

    Use can use .html method alternatively to get the entire html data of the page.

    $(function(){
        var a = ($('html').html())
    })​
    
    0 讨论(0)
  • 2021-02-07 19:38

    I don't understand whatyou mean that you must make modifications, but you could simply load the second page through AJAX

    var url ="1.html";
    $.ajax({
      url: url,
      dataType: 'html'
      success: function(data){
                 //do something with data, which is the page 1.html
               }
    
    });
    
    0 讨论(0)
  • 2021-02-07 19:43

    jQuery:

    $.get('ajax/test.html', function(data) {
      $('.result').html(data);
      alert('Load was performed.');
    });
    
    0 讨论(0)
  • 2021-02-07 19:51

    To get the DOM converted to a string:

    document.getElementsByTagName('html')[0].innerHTML
    

    Question: what do you mean by "use it"? Do you need to include 1.html inside 2.html? Or do you just need to process it?

    0 讨论(0)
  • 2021-02-07 19:55

    Its very simple

    On 2.html use this jQuery snippet

    $.get("1.html", function(response) { 
        alert(response) 
        //do you operations
    });
    
    0 讨论(0)
提交回复
热议问题