在客户端的GWT应用程序中,我生成了一个包含HTML内容的字符串,并将其传递给一个函数,该函数在新选项卡中打开它。我已经编写了一个CSS文件来设置HTML内容的样式,并给出了一个指向它的链接。但是我的HTML文件没有样式化。
public void writeHtml(){
StringBuffer html = new StringBuffer();
html.append("<!DOCTYPE html>");
html.append("<html lang=\"en\">");
html.append("<head>");
html.append("<title>Hello World</title>");
html.append("<meta charset=\"utf-8\">\n" +
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n");
html.append("<link href=\"StyleSheet.css\" rel=\"stylesheet\" type=\"text/css\">");
html.append("</head>");
html.append("<body>\n" +
"\n" +
"<h1>This is a heading</h1>\n" +
"<p>This is a paragraph.</p>\n" +
"\n" +
"</body>\n" +
"</html>");
openPrintWindow(html.toString());
}
public native void openPrintWindow(String contents) /*-{
var printWindow = window.open("", "PrintWin", false);
printWindow.document.open("text/html","replace");
if (printWindow && printWindow.top) {
printWindow.document.write(contents);
} else {
alert("The print feature works by opening a popup window, but our popup window was blocked by your browser. If you can disable the blocker temporarily, you'll be able to print here. Sorry!");
}
}-*/;
CSS文件- StyleSheet.css
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p {
color: red;
font-family: courier;
font-size: 160%;
}
那么,问题出在哪里,我错在哪里呢?
https://stackoverflow.com/questions/56556903
复制相似问题