I am currently working on an application using Django. Within one of my HTML pages, I need to display a receipt. There are two print buttons available: print_btn and print_btn_new, each with distinct styles. To accommodate these styles, I have created two separate stylesheets called print.css and print_new.css.
In the header section
<link rel="stylesheet" href="{% static 'css/print.css' %}" id="printCss" media="print">
Everything appears to be working correctly. However, when the user clicks on print_btn_new, the printed receipt does not reflect the intended CSS styling.
For the print_btn_new
<button id="print_btn_new" onclick="printNewOnClicked();" name="button">Print New</button>
The printNewOnClicked() function :
function printNewOnClicked(){
document.getElementById('printCss').href = '{% static 'css/print_new.css' %}';
alert(document.getElementById('printCss').href);
window.print();
}
Interestingly, the alert message correctly displays the URL for print_new.css. Despite this, manually inputting the URL from the alert box into the address bar results in displaying the correct file.