传递大JSON对象到另一个网页在新窗口。 [英] Passing large JSON object to another page in a new window.

查看:145
本文介绍了传递大JSON对象到另一个网页在新窗口。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提前道歉,如果这已经回答了。我GOOGLE了周围的几个小时,现在,我还没有发现任何东西,似乎回答我确切的问题。

I apologize in advance if this has already been answered. I've Googled around for a few hours now, and I still haven't found anything that seems to answer my exact question.

从本质上讲,我有一个非常复杂的/高风格的视图,它显示的是从数据库中抽取用户特定的数据。我已经捕获的数据作为JSON对象,使用.DATA附之于身体我的网页()。我已经添加了一个按钮,检索JSON对象,并打开我的打印机友好的页面在一个新窗口。我希望能够访问/从在这个新窗口操纵用户特定的JSON对象。 (这都将是在同一个域。)

Essentially, I have a very complex/highly styled view which is displaying user-specific data pulled from the database. I've captured the data as a JSON object, attached it to the body my page using .data(). I've added a button that retrieves the JSON object and opens my printer friendly page in a new window. I want to be able to access/manipulate the user-specific JSON object from within this new window. (This would all be on the same domain.)

大多数我见过的解决方案似乎周围打开一个新的空白窗口为中心。我并不想这样做。我有codeD的页面布局,我计划有的JavaScript / CSS这也运行。我见过涉及打开一个新的窗口,然后使用文件撰写,这将是巨大的,如果有一种方式为目标的新页面上的特定元素的解决方案。我试过,例如:

Most of the solutions I've seen seem to be centered around opening a new, blank window. I don't want to do that. I've coded a layout for the page, and I plan on having javascript/css which also runs. I've seen solutions that involve opening a new window and then using document.write, which would be great, if there was a way to target a specific element on the new page. I've tried, for example:

x = window.open(url);
x.document.write(myJson);

这也把新的页面上的JSON对象,但完全抹布一切我已经在布局。

Which does put the JSON object on the new page, but completely wipes everything else I had in the layout.

我也看到了提示字符串化,然后base64编码对象的解决方案。但我担心的URL长度的限制,因为它们可能被点击按钮之前收集此页面上的大量数据。

I've also seen solutions that suggest stringifying and then Base64 encoding the object. But I'm concerned about URL length restrictions, given that they could potentially be gathering a lot of data on this page before clicking the button.

我也看到,建议使用HTML5本地存储解决方案。我想我会做的,如果没有更好的解决办法。然而HTML5提出了浏览器兼容性问题,而且我preFER,以避免他们,如果可能的。

I've also seen solutions that suggest using HTML5 local storage. Which I suppose I'll do, if there's no better solution. However HTML5 raises browser compatibility issues, and I'd prefer to avoid them if possible.

下面是一些例子code:

Here's some example code:

JSON对象:

{ 
{
"name":"Percy Pea.",
"bio":"Percy Pea was born in a pod, and lived there happily."
},
{
"name":"James Cob",
"bio":"James Cob was arrested for stalking."
}
}

我抓住,当它回来从服务器为数据:

I capture that when it comes back from the server as 'data':

$("body").data( "userData", data);

在我的onclick打印机友好的页面按钮,检索到的JSON对象:

In my onclick for the printer friendly page button, I retrieve the JSON object:

var userData = $("body").data("userData");

那么,这是可行的?有没有这样的方式打开一个新的窗口,然后再插入/附加数据里面一个特定的元素?还是......也许一些其他的方式,我还没有考虑。

So is this doable? Is there so way to open a new window, and then insert/attach data to a specific element inside it? Or...maybe some other way I haven't even considered.

在此先感谢您的帮助,虽然我也一定会复选标记的答案,一旦它的发布。

Thanks in advance for any help, although I will also be sure to check-mark the answer, once it's posted.

推荐答案

您可以保存在全局变量的JSON在父窗口引用它在弹出的窗口中code

you can save the json in global variable in the parent window and reference it in your popup window code

http://stackoverflow.com/a/87737/1755374

这篇关于传递大JSON对象到另一个网页在新窗口。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆