Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i want to print div content i write a code for that is
HTML
 <script type="text/javascript">
           function printdiv(printpage){
               var headstr="<html><head><title></title></head><body>";
               var footstr="</body>";
               var newstr=document.all.item(printpage).innerHTML;
               var oldstr=document.body.innerHTML;
               document.body.innerHTML=headstr + newstr + footstr;
               window.print();
               document.body.innerHTML=oldstr;
               return false;
           }
</script>

when i run this it shows error : Uncaught SyntaxError: Unexpected identifier,and line on var headstr="&lt;html>&lt;head>&lt;title>&lt;/title>&lt;/head>&lt;body>";


please help me...
Posted
Updated 25-Jan-16 0:06am
v2
Comments
dan!sh 25-Jan-16 6:06am    
You have been a member for almost 2 years, asked 23 questions and you still don't bother to ask it properly? How tough is it to format the code here?
Member 10575434 25-Jan-16 6:11am    
sorry...but please help me..

1 solution

Hey hi,

Create a new div on page add id to it

set the innerhtml of the div

Then use window.print to print that element or the section
I think you cannot print the string directly unless it gets rendered.
 
Share this answer
 
Comments
Member 10575434 25-Jan-16 7:10am    
how to add innerhtml please tel me
Member 10575434 25-Jan-16 7:16am    
please write a code for that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900