title: Passing HTML to javascript function
body: <p>I have a variable in which a complete html is saved. 
  $body= $myhtmlpage;</p>
  
  <pre><code>&lt;a onclick="openWin(' &lt;?php echo htmlspecialchars(json_encode($body)) ?&gt;');" href="javascript:void(0);"&gt; Click &lt;/a&gt;
  </code></pre>
  
  <p>and i have this javascript function which display the text in new window.</p>
  
  <pre><code> &lt;script type="text/javascript"&gt;
  function openWin( str )
  {
  myWindow=window.open('','','width=400,height=400');
  myWindow.document.write(str+"&lt;p&gt;This is 'myWindow'&lt;/p&gt;");
  myWindow.focus();
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>When there is simple text in my body, it works fine. but if there is some html then it does not display, I am new to javascript. please tell me how can i prepare my HTML that it should be passed to Javascript html. i tried <strong><code>htmlspecialchars(json_encode($body))</code></strong> 
  functions but still having problem.</p>
  
  <pre><code>Uncaught SyntaxError: Unexpected identifier 
  </code></pre>