【发布时间】:2019-08-21 06:33:21
【问题描述】:
我想为要打印的部分添加样式。
let popupWinindow
let innerContents = this.printDiv.nativeElement.innerHTML;
popupWinindow = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto');
popupWinindow.document.open();
popupWinindow.document.write('<html><head><link href="styles.css" rel="stylesheet" type="text/css"></head><body onload="window.print();">' + innerContents + '</html>');
popupWinindow.document.close();
当我在样式标签内部添加样式时,一切正常。 但是当我尝试以外部方式添加它时,它不适用于 printDiv。
这是我在控制台中遇到的错误。
Refused to apply style from 'http://localhost:4200/styles.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
【问题讨论】:
-
查看post
-
尝试下载localhost:4200/styles.css,在浏览器地址栏输入,确认得到的是css文档而不是404 html错误页面
-
我收到一个错误页面,我该怎么办?所以,它会自动获得访问权限
-
您应该使用样式表的完整绝对路径(包括协议和域)
标签: javascript angular angular7 angular8