0

I am trying to add a print button inside the window thats created by js. But its showing [object Window] instead of showing the link or button. What is an alternative solution?

jQuery(function($) {

$('a.print').click(function(){

var print_button = '<a href="javascript:window.print();" class="print">Print</a>';
var print_page = window.open('','Print','width=600,scrollbars=yes, height=700');
var html = print_page + '<h2><?php print t("Term & Condition"); ?></h2> <br/>' + 'somethings';
print_page.document.open();
print_page.document.write(html);
print_page.document.close();

return false;

}); 

}); 

2 Answers 2

1

If I got your question right,

function printDiv(divName) {
         // divName - is the div to be printed
         var printContents = document.getElementById(divName).innerHTML; // get the div content
         var originalContents = document.body.innerHTML; //get a copy of original content
         document.body.innerHTML = printContents; //set the div content to body
         window.print(); // print 
         document.body.innerHTML = originalContents; // revert back to original content
} 

Pass the div name that's is to be printed. There are a lot of jquery plugins which will allow you to help you out. Try googling.

If I'm mistaken your question correct me, I might be able to help you out.

Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure what you are trying to do. But I feel this line maybe wrong because it has print_page which is an object and I think it should be print_button. And print_page is a object and that's why you see [object Window]

var html = print_page + '<h2><?php print t("Term & Condition"); ?></h2> <br/>' + 'somethings';

Correct line is,

var html = print_button + '<h2><?php print t("Term & Condition"); ?></h2> <br/>' + 'somethings';

1 Comment

I agree having print_page instead of print_button is probably a mistake and should fix the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.