Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of one-machine double-screen and double-screen communication scheme

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

One web machine and two screens are needed in the project, that is, one computer, two screens, each screen displays part of the content, and there is no need for real-time communication and interaction between the two web tabs. Here is a brief introduction to the thinking and final solution to this problem in the project:

One: the solution of opening two tabs

1. If the tab you open is fixed, you can directly add the target= "_ blank" attribute to the a tag. For example, the code for opening Bing home page is: Bing home page

two。 If the page address is dynamic, you can use the window.open (url) method of js.

There are two points to note:

The first security issue: if the parent page and the newly opened page poem have a different domain name, the browser will prevent the new window from accessing the content in the opener, but the url of the parent page can be rewritten through window.opener.location=newURl, even if it is different from the domain of the parent page. If the parent window doesn't do anything to prevent it from being embedded by iframe, you can use iframe to make a phishing page. If you don't pay attention to url, you may be phished.

The second performance problem: chrome each tab is a separate process, and then the process contains many threads, but if the a tag through the target= "_ blank" or window.open (url) to open the page in the new window, the child window will share processes and threads with the parent window, if the child window carries out complex operations or requests, then the parent window is very likely to be stuck.

Cracking method:

1. By adding this noopener attribute to the a tag, you can set the opner of the newly opened window to empty.

2.window.open and set opner to empty

1 var newWindow= window.open ('xxx'); 2 newWindow.opener = null; II: dual screen communication scheme

1.localStorage

Realize the communication between different pages in the same browser by monitoring the data changes of localStorage (cross-domain is not applicable, it needs to be combined with postmessage). When there is a large amount of communication on double screens, it is recommended to use it quickly and conveniently.

It is recommended that the lsbridge library be applied directly.

2.WebSocket

With regard to websocket, there is no longer a detailed explanation. In the summary of push technology on the server side of the blog, there is a detailed explanation.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 223

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report