简体   繁体   English

如何在多个浏览器窗口中从现有页面拆分DOM?

[英]How to split the DOM from an existing page across multiple browser windows?

I'd like to be able to take the DOM structure from an existing page and then separate certain elements across different browser windows. 我希望能够从现有页面获取DOM结构,然后在不同的浏览器窗口中分隔某些元素。 When doing so, I'd like to retain the same session across each of these browser windows. 这样做时,我希望在每个浏览器窗口中保留相同的会话。 Is this possible? 这可能吗? And if so, how would one go about doing this? 如果是这样,怎么会这样做呢?

To give more clarity, here's an example of how this would be used: 为了更清楚,这里是一个如何使用它的示例:

1) I login to a site and create the session. 1)我登录网站并创建会话。

2) The site has various widgets on the page. 2)该网站在页面上有各种小部件。 Some of the widgets I need to use, some I do not. 我需要使用的一些小部件,有些则不然。 Instead of hiding the ones I don't need via CSS, I'd rather extract the ones I do need into separate windows. 而不是通过CSS隐藏我不需要的那些,我宁愿将我需要的那些提取到单独的窗口中。 Then I could arrange those individual widget windows across my desktop as much as I want. 然后,我可以根据需要在我的桌面上安排这些单独的小部件窗口。

Any way to do this? 有什么办法吗? Thanks. 谢谢。

I'd like to retain the same session across each of these browser windows. 我想在每个浏览器窗口中保留相同的会话。

Sessions are not maintained by the DOM. DOM不会维护会话。 They exist in cookies and maybe javascript state. 它们存在于cookie中,也可能是javascript状态。

I'd like to be able to take the DOM structure from an existing page and then separate certain elements across different browser windows. 我希望能够从现有页面获取DOM结构,然后在不同的浏览器窗口中分隔某些元素。

There are two options, DOM nodes can be directly transplanted from one document to via adoptNode but that requires direct access between the different javascript global contexts, which is only available via frames or window.opener , ie when one window directly spawned the other. 有两个选项,DOM节点可以直接从一个文档移植到adoptNode,但是需要在不同的javascript全局上下文之间直接访问,这只能通过frames或window.opener获得 ,即当一个窗口直接产生另一个窗口时。 Note that this just moves DOM nodes, not any state or listeners associated with them. 请注意,这只会移动DOM节点,而不是任何与它们关联的状态或侦听器。

The alternative is serializing them to HTML or XML and sending the serialized form to another window via various communication mechanisms such as postMessage or channels. 另一种方法是将它们序列化为HTML或XML,并通过各种通信机制(如postMessage或通道)将序列化表单发送到另一个窗口。

Since you say widgets I guess there is some javascript associated with them. 既然你说小部件,我想有一些javascript与他们相关联。 That javascript will have to be rewritten to communicate across window boundaries in a similar fashion as you move the DOM nodes themselves across window boundaries. 当你跨越窗口边界​​移动DOM节点本身时,必须重写javascript以跨越窗口边界​​进行通信。

If your frontend is implemented as MVC or similar patterns you should just move the model to a different window and rematerialize the view instead of moving the dom directly. 如果您的前端实现为MVC或类似模式,您应该将模型移动到不同的窗口并重新实现视图而不是直接移动dom。

If you want display different elements among some page, maybe you could try to use localStorage to share message with different tabs on one browser. 如果要在某个页面中显示不同的元素,也许您可​​以尝试使用localStorage在一个浏览器上与不同的选项卡共享消息。 When a page is opened set an identity for it and save to localStorage, and every page listen to the change of localStorage. 打开页面时为其设置标识并保存到localStorage,每个页面都会监听localStorage的更改。 Then you could control what will be displayed on one window by set localStorage to share settings. 然后,您可以通过设置localStorage来共享设置来控制将在一个窗口上显示的内容。

But your second part of example may not a good idea because a browser window have many same part, them can not be hide and useless and them could not be set on the top. 但是你的第二部分示例可能不是一个好主意,因为浏览器窗口有许多相同的部分,它们不能隐藏和无用,并且它们无法设置在顶部。 Make a desktop app would fix this problem but in today web developer ways normally in a webpage you could move or hide some widgets. 制作一个桌面应用程序可以解决这个问题,但在今天的Web开发人员通常在网页中的方式,您可以移动或隐藏一些小部件。 So you could think about this way or try to achieve your thoughts by above way. 所以你可以考虑这种方式或尝试通过上述方式实现你的想法。

Hope this can help you in some way. 希望这可以在某种程度上帮助你。

You can use Multi Layout Manager for Chrome . 您可以使用Multi Layout Manager for Chrome This way you can arrange your windows as you like and save them for later usage. 这样您就可以根据需要排列窗口并保存以供日后使用。 You can use web sockets (WinRT or SignalR) to sync and communicate among windows. 您可以使用Web套接字(WinRT或SignalR)在Windows之间进行同步和通信。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM