Print a div using javascript in angularJS single page application

前端 未结 7 1014
野性不改
野性不改 2020-11-28 02:44

I have a single page web application using angularJS. I need to print a div of certain page. I tried the following:

The page contains few div (print.html)

         


        
7条回答
  •  天涯浪人
    2020-11-28 03:19

    I done this way:

    $scope.printDiv = function (div) {
      var docHead = document.head.outerHTML;
      var printContents = document.getElementById(div).outerHTML;
      var winAttr = "location=yes, statusbar=no, menubar=no, titlebar=no, toolbar=no,dependent=no, width=865, height=600, resizable=yes, screenX=200, screenY=200, personalbar=no, scrollbars=yes";
    
      var newWin = window.open("", "_blank", winAttr);
      var writeDoc = newWin.document;
      writeDoc.open();
      writeDoc.write('' + docHead + '' + printContents + '');
      writeDoc.close();
      newWin.focus();
    }
    

提交回复
热议问题