我有以下HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function init() {
var x = document.getElementById("MAIN");
console.log("clientWidth:" + x.clientWidth.toFixed());
}
</script>
</head>
<body onload="init()">
</div>
<div id="MAIN">
<p>Check</p>
</div>
</body>
</html>
在Chrome,IE11和QtWeb中,控制台显示非零结果,这是我所期望的,例如:
clientWidth:1219
但是,如果我尝试使用wkhtmltopdf转换它,我总是得到0作为答案:
$ wkhtmltopdf.exe --debug-javascript wktest.html wktest.pdf
Loading pages (1/6)
Warning: file:///C:/work/pm_doc/test/wktest.html:6 clientWidth:0
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
我也尝试过使用window.computedStyle(element).width
- 同样的结果。在wkhtmltopdf下运行javascript时如何获取元素显示宽度?