Print the Div Contents in Php or Javascript

The JavaScript is below..

<script type="text/javascript">
var base_url="<?php echo $this->request->webroot; ?>";

function printDivContents(divID="xshr_print_section") {

    //Get the HTML of div
    var divElements = document.getElementById(divID).innerHTML;
    
    Popup(divElements);
}


function Popup(data) {
    var mywindow = window.open('', 'new div', 'height=400,width=600');
    mywindow.document.write('<html><head><title></title>');
    mywindow.document.write('<link rel="stylesheet" href="'+base_url+'"css/print.css" type="text/css" />');
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);
    mywindow.document.write('</body></html>');

    mywindow.print();

    return true;
}
</script>

The HTML file is like-

<div id="xshr_print_section">
<!-- here the printing Contents -->

-
-
-
</div> 

JQuery AJAX syntax

var data="abc";
$.ajax({
    type: "POST",
    url: "page.php",
    data: {
        "data":data,
    },
    dataType: "json",

    //if received a response from the server
    success: function( datas, textStatus, jqXHR) {

    },

    //If there was no resonse from the server
    error: function(jqXHR, textStatus, errorThrown){

    },

    //capture the request before it was sent to server
    beforeSend: function(jqXHR, settings){

    },

    //this is called after the response or error functions are finished
    //so that we can take some action
    complete: function(jqXHR, textStatus){

    }

}); 

Print a div contents in Php

If You want to print the section or Div contents, then please do the following…

By using the following code you can print the contents in a div or section.

 

Html  Section:

// The Printing button. On click this button the print preview opens


<div class="row">
      <div class="col-md-12"> 
              <button class="xshr_print_section_btn" onclick="javascript:printDivContents('xshr_print_section')">Print Details</button></div>
</div>

<!-- html Ends -->

Script Section:

<!-- For Print the Contents Starts -->

<script language="javascript" type="text/javascript">

function printDivContents(divID) {

//Get the HTML of div
var divElements = document.getElementById(divID).innerHTML;

//Get the HTML of whole page
var oldPage = document.body.innerHTML;

//Reset the page's HTML with div's HTML only
document.body.innerHTML = 
"<html><head><title></title></head><body>" + 
divElements + "</body>";

//Print Page
window.print();

//Restore orignal HTML
document.body.innerHTML = oldPage;


}
</script>

<!-- For Print the Contents / Ends-->

 

 

also solution available at: how to print a Div content in javascript

How to Update the Current Browser URL

# UPDATE THE CURRENT URL IN BROWSER::
<script>

ChangeUrl = function(page, url) {

    if (typeof (history.pushState) != "undefined") {

        var obj = { Page: page, Url: url };

        history.pushState(obj, obj.Page, obj.Url);

        $('.breadcrumb-get-a-pro').attr('href', url);

    } else {

        alert("Browser does not support HTML5.");

    }

}

</script>