locked
how to add section head iframe into window print RRS feed

  • Question

  • User-1634604574 posted

    i wrote this code but i get blank white page print

       var sWinHTML = $("#div_content_print iframe").contents().find('body')[1];
                 var sWinHTML2 = $("#div_content_print iframe").contents().find('head')[1];
    
                var winprint = window.open("", "");
    
              
                winprint.document.write(sWinHTML2.innerHTML);
                winprint.document.write(sWinHTML.innerHTML);
               
    
                winprint.document.close(); 
                winprint.focus(); 
    
                winprint.print();
                winprint.close();
    
                return true;

    Friday, January 17, 2020 6:32 PM

All replies

  • User-474980206 posted

    in general the <head> contents has no printable content. 

    also generally there is only one head and  one body in a document so body[1]  & head[1] are undefined

    note: one check with the debugger would tell you this. Have you not learned about debuggers yet?

    Friday, January 17, 2020 8:58 PM
  • User475983607 posted

    This is a duplicate post.  Is there any reason why you did not use the code in the working example?  Why are you breaking the code?

    https://forums.asp.net/t/2163280.aspx?how+to+set+div+content+into+another+div

    Friday, January 17, 2020 10:53 PM
  • User288213138 posted

    Hi zhyanadil,

    how to add section head iframe into window print

    As bruce said,<head> contents has no printable content, can you show me your html page?

    var sWinHTML = $("#div_content_print iframe").contents().find('body')[1];
                 var sWinHTML2 = $("#div_content_print iframe").contents().find('head')[1];

    Under normal circumstances, the content of the frame should be the following code:

    var sWinHTML = $("#div_content_print iframe").contents().find('body')[0];
    var sWinHTML2 = $("#div_content_print iframe").contents().find('head')[0];

    Best regards,

    Sam

    Saturday, January 18, 2020 3:31 AM