0

I have my html in a php variable say $html and I want to print this html using javascript. I have written following code for this.

<script>var mywindow = window.open('', 'my div', 'height=400,width=600');
    mywindow.document.write(<?= $html ?>);
    mywindow.print();</script>

It works for me if variable contains normal string not HTML

1
  • There is no error in your code. I personally ran it now and it works. Commented Aug 2, 2016 at 10:15

2 Answers 2

2

Try to use quotes in write function like,

mywindow.document.write("<?= $html ?>");
Sign up to request clarification or add additional context in comments.

2 Comments

all the code is within php file and it is like mywindow.document.write($html);
If the html is on another page then you can set $_SESSION['html'] and then after printing you can unset it.
0

You need comas:

mywindow.document.write('<?= $html ?>');

Comments

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.