title: window.open, source code viewer and highlight.js
body: <p>I'm actually trying to make a source code viewer for website based on AJAX and popups windows. This will allowing to me to customize the viewer. I'm using hightlight.js for syntaxing, but it's the first time I use that libray.</p>
  
  <p>The process is simple:</p>
  
  <ol>
  <li>I'm getting the page HTML with its URL using AJAX (here I'm using
  jQuery)</li>
  <li>I put the resulted content in a window and show it.</li>
  <li>On the window, Highlight.js is (supposed) to get the code colorized</li>
  </ol>
  
  <p>Similar to this topic: <a href="https://stackoverflow.com/questions/1815021/programmatically-open-view-source-html-window-in-browser-with-">Programmatically open &quot;View Source&quot; HTML Window in Browser with Javascript?</a> but with syntax highlighting in addition. Unfortunely the window is shown with the code inside, but that one is not colorized.</p>
  
  <p>This is the entire function (it provides a fallback for cross-origin requests)</p>
  
  <pre><code>function show_source(link) {
      $.ajax({
          method: "GET",
          url: link,
          dataType: "html",
          success: function (data) {
              var source = data;
              //parse special chars
              source = source.replace(/&lt;/g, "&amp;lt;").replace(/&gt;/g, "&amp;gt;");
              // add &lt;pre&gt; tags to preserve whitespace
              source = "&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;link rel='stylesheet' href='/css/include/default.css'&gt;&lt;script src='/lib/include/highlight.pack.js'&gt;&lt;/script&gt;&lt;script&gt;hljs.initHighlightingOnLoad(document.getElementById('code'));&lt;/script&gt;&lt;/head&gt;&lt;body&gt;&lt;pre id='code' class='html'&gt;" + source + "&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;";
              //now open the window and set the source as the content
              var sourceWindow = window.open('', 'Source code of ' + link + '', 'height=800,width=800,scrollbars=1,resizable=1');
              if (!sourceWindow || sourceWindow.closed || typeof sourceWindow.closed == 'undefined') {
                  alert("Please allows this popup window to be shown");
              } else {
                   sourceWindow.document.write(source);
                  sourceWindow.document.close(); //close the document for    writing, not the window
                  //give source window focus
                  if (window.focus) {
                      sourceWindow.focus();
                  }
              }
          },
          error: function(){
              window.open("view-source:"+link+"", "_blank");
          }
      });
  }
  </code></pre>
  
  <p>But I verified my code many times and everything seems fine. Firefox dev tools indicated that CSS and JS file are loaded successfully (GET) and no JS errors.
  Where is the problem? Thanks to help me.</p>
  
  <p>EDIT: added a missing parenthesis but not working much.</p>