如何在wkhtmltopdf中使用本地存储

时间:2022-05-29 17:11:20

To display an item (whose key is "myinfo"), previously stored locally in the browser, I use something like:

要显示以前在浏览器中本地存储的项目(其键为“myinfo”),我使用如下内容:

$('div:first').html( localStorage.getItem('myinfo') ); 

It works well until I open a PDF generated on this page using wkhtmltopdf. In that case, my DIV's content is empty, showing that the localStorage function returned null.

它运行良好,直到我打开使用wkhtmltopdf在此页面上生成的PDF。在这种情况下,我的DIV内容为空,表明localStorage函数返回null。

Now that would suggest to me that the webkit engine underneath wkhtmltopdf does not implement localStorage.

现在,我建议wkhtmltopdf下面的webkit引擎不实现localStorage。

Is that the correct reason for this behaviour?

这是这种行为的正确理由吗?

How else can I store and retrieve stuff locally using javascript and wkhtmltopdf?

如何使用javascript和wkhtmltopdf在本地存储和检索内容?

1 个解决方案

#1


0  

Now, I've thought through, and can answer the first part of my question:

现在,我已经考虑过了,可以回答我问题的第一部分:

Is that the correct reason for this behaviour?

这是这种行为的正确理由吗?

No, it isn't.

不,不是。

The reason my approach won't work is:

我的方法不起作用的原因是:

I saved some data to local storage on "page1.html" in Browser1. Now going to "page2.html" on the same browser, I called wkhtmltopdf (via an AJAX request to the server). Since wkhtmltopdf is essentially another browser (let's call it "Browser2"), there's no way it's going to be able to access data that was previously saved by "Browser1".

我在Browser1的“page1.html”上保存了一些数据到本地存储。现在在同一个浏览器上转到“page2.html”,我调用了wkhtmltopdf(通过AJAX请求到服务器)。由于wkhtmltopdf本质上是另一个浏览器(我们称之为“Browser2”),因此无法访问之前由“Browser1”保存的数据。

Therefore, it's looking increasing to me like: there's no way to programmatically persist data between my Browser1 and wkhtmltopdf without first saving that data on the server. If I am wrong, then my second question:

因此,它看起来越来越像我:没有办法在我的Browser1和wkhtmltopdf之间以编程方式持久保存数据,而无需先在服务器上保存这些数据。如果我错了,那么我的第二个问题:

How else can I store and retrieve stuff locally using javascript and wkhtmltopdf?

如何使用javascript和wkhtmltopdf在本地存储和检索内容?

is still waiting for an answer!

还在等待答案!

#1


0  

Now, I've thought through, and can answer the first part of my question:

现在,我已经考虑过了,可以回答我问题的第一部分:

Is that the correct reason for this behaviour?

这是这种行为的正确理由吗?

No, it isn't.

不,不是。

The reason my approach won't work is:

我的方法不起作用的原因是:

I saved some data to local storage on "page1.html" in Browser1. Now going to "page2.html" on the same browser, I called wkhtmltopdf (via an AJAX request to the server). Since wkhtmltopdf is essentially another browser (let's call it "Browser2"), there's no way it's going to be able to access data that was previously saved by "Browser1".

我在Browser1的“page1.html”上保存了一些数据到本地存储。现在在同一个浏览器上转到“page2.html”,我调用了wkhtmltopdf(通过AJAX请求到服务器)。由于wkhtmltopdf本质上是另一个浏览器(我们称之为“Browser2”),因此无法访问之前由“Browser1”保存的数据。

Therefore, it's looking increasing to me like: there's no way to programmatically persist data between my Browser1 and wkhtmltopdf without first saving that data on the server. If I am wrong, then my second question:

因此,它看起来越来越像我:没有办法在我的Browser1和wkhtmltopdf之间以编程方式持久保存数据,而无需先在服务器上保存这些数据。如果我错了,那么我的第二个问题:

How else can I store and retrieve stuff locally using javascript and wkhtmltopdf?

如何使用javascript和wkhtmltopdf在本地存储和检索内容?

is still waiting for an answer!

还在等待答案!