Write Content To New Window with JQuery

前端 未结 4 721
名媛妹妹
名媛妹妹 2020-11-30 03:08

I have a web page with a DIV element in it. When a user clicks \"print\", I want to print the contents of that div. Please note, I only want to print the contents of the DIV

相关标签:
4条回答
  • 2020-11-30 03:30

    I found a pretty perfect match of a tutorial for exactly that.. http://www.bennadel.com/blog/1591-Ask-Ben-Print-Part-Of-A-Web-Page-With-jQuery.htm

    Additionally, you can attact print-only CSS to the page that has everything but what you want turned off.

    0 讨论(0)
  • 2020-11-30 03:37

    You can use

    $(w.document.body).html(html);
    

    See this example

    0 讨论(0)
  • 2020-11-30 03:39

    file1:

    function find(input){
        return $(input);
    }
    
    function printClick() {
      var w = window.open();
      var html = $("#divToPrintID").html();
    
      // how do I write the html to the new window with JQuery?
    }
    

    and in the second file do that:

    var html = window.opener.find("#divToPrintID").html();
    
    0 讨论(0)
  • 2020-11-30 03:51

    Try -

    var w = window.open();
    var html = $("#divToPrintID").html();
    w.document.writeln(html);
    

    Reference - http://www.javascripter.net/faq/writingt.htm

    0 讨论(0)
提交回复
热议问题