0

I have a function in head, function is -

<script type="text/javascript">
        $("#btnPrint").live("click", function () {
            var divContents = $("#page-wrap").html();
            var printWindow = window.open('', '', 'height=400,width=800');
            printWindow.document.write('<html><head><title>DIV Contents</title>');
            printWindow.document.write('</head><body>');
            printWindow.document.write(divContents);
            printWindow.document.write('</body></html>');
            printWindow.document.close();
            printWindow.print();
        });
    </script>

problem is part of the above function showing in the body tag and off course web page.

this is the part of js code that showing in web page

'); printWindow.document.close(); printWindow.print(); }); 

I have test the code in one server look like this -

<script type="text/javascript">

    $("#btnPrint").live("click", function () {
        var divContents = $("#page-wrap").html();
        var printWindow = window.open('', '', 'height=400,width=800');
        printWindow.document.write('<html><head><title>DIV Contents</title>');
        printWindow.document.write('</head><body>');
        printWindow.document.write(divContents);
        printWindow.document.write('</body></html>');
        printWindow.document.close();
        printWindow.print();
    });

and another server code looking like this-

<script type="text/javascript">

    $("#btnPrint").live("click", function () {
        var divContents = $("#page-wrap").html();
        var printWindow = window.open('', '', 'height=400,width=800');
        printWindow.document.write('<html><head><title>DIV Contents</title>');
        printWindow.document.write('</head><body >');
        printWindow.document.write(divContents);
        printWindow.document.write('<script type="text/javascript">window.NREUM||(NREUM={});NREUM.info={"beacon":"bam.nr-data.net","licenseKey":"2aa6bb7413","applicationID":"18758918","transactionName":"MlFbYRRZWBdSWkcPWwsbbEcPF1kWV1xBSEQNRA==","queueTime":0,"applicationTime":50,"atts":"HhZYF1xDSxk=","errorBeacon":"bam.nr-data.net","agent":""}

I don't understand what is the problem . Any help greatly appreciated ! thanks .

  • See [this](http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice) . Do not use `document.write()` – Raptor Jun 03 '16 at 07:33
  • @Raptor, for new windows and iframes, `document.open`, `write` and `close` is just fine. – Kaiido Jun 03 '16 at 07:34
  • Are you sure you don't have a `` in a string somewhere that you don't show us ? http://stackoverflow.com/questions/236073/why-split-the-script-tag-when-writing-it-with-document-write – Kaiido Jun 03 '16 at 07:41
  • I checked "" nothing like this @kaiido – full stack Jun 03 '16 at 07:46
  • in which browser are you experiencing it ? – Kaiido Jun 03 '16 at 07:46
  • Chrome Version 50.0.2661.102 m and mozila version 46.0.1 both – full stack Jun 03 '16 at 07:52
  • Can't repro... sorry. I can't get where it does come from either. But for a fix, try to escape `'`. – Kaiido Jun 03 '16 at 07:55
  • @Kaiido this script add automatically could you please suggest me what is the problem script is – full stack Jun 03 '16 at 13:37

0 Answers0