如何在Wkhtmltopdf / wkhtmltoimage上运行自定义Javascript? [英] How to run custom Javascript on Wkhtmltopdf/wkhtmltoimage?
本文介绍了如何在Wkhtmltopdf / wkhtmltoimage上运行自定义Javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在网站上运行javascript,但是当我这样做时,没有任何变化,我得到的pdf好像我没有运行javascript的结果,这是我做的一个例子:
I want to run a javascript on a website, but when I do it, nothing changes, I get the pdf as if I run no result of the javascript on it, this is an example of what I do:
xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltoimage --run-script "javascript:(\$(function(){ \$("div").hide() ;}))" google.com google.png
我还有没有jquery的脚本,如:
I have also scripts without jquery like:
xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltopdf --run-script "javascript:(function(){ document.write("AHHHHHHHHHHHHHHHHHHHHHHHHHHHHH"); ;})" google.com p2.pdf
但正如我所说,对pdf或png没有影响(因为我已尝试过wkhtmltoimage和wkhtmltopdf)。
But as I said, no effect on the pdf or the png (because I have tried both wkhtmltoimage and wkhtmltopdf).
推荐答案
您的命令错误地使用了引号;试试这个:
Your command uses quotes incorrectly; try this:
--run-script "javascript:(\$(function(){ \$('div').hide() ;}))"
此外,尝试增加JavaScript延迟:
Also, try increasing the JavaScript delay:
--javascript-delay 1000
http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
这篇关于如何在Wkhtmltopdf / wkhtmltoimage上运行自定义Javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文