A front-end-based browser cross-domain information interaction method, apparatus, and device

CN116962380BActive Publication Date: 2026-11-17BEIJING ZHONGHONG LIDA TECH DEV CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310907716.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-21
Publication Date
2026-11-17
Estimated Expiration
2043-07-21

Smart Images

  • Figure CN116962380B_ABST
    Figure CN116962380B_ABST
Patent Text Reader

Abstract

This application relates to a front-end-based browser cross-domain information interaction method, apparatus, and device, applied in the field of browser cross-domain communication technology. The method includes: in response to a first window page's subscription operation to a second window page, generating a subscription identifier for the first window page; the first window page calling a message subscription publishing plugin to transmit its subscription mapping information, and storing the subscription mapping information in a message mapping pool; the second window page publishing a subscription message and calling the message subscription publishing plugin to transmit the subscription message; and broadcasting the transmitted subscription message to the first window page according to the subscription mapping information stored in the message mapping pool. This application overcomes the shortcomings of server-based cross-domain communication, such as high server requirements, high cost, and long communication time, achieving low-cost, high-efficiency, server-free, and low-limitation real-time cross-domain communication.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of browser cross-domain communication technology, and in particular to a front-end-based browser cross-domain information interaction method, apparatus and device. Background Technology

[0002] Cross-domain communication on the Internet mainly includes communication between different ports of the same domain name, between different protocols of the same domain name, between domain names and their corresponding IP addresses, between the same main domain but different subdomains, between the same domain name but different second-level domains, and between different domain names.

[0003] Browsers restrict direct communication between cross-domain and cross-window pages for security reasons. However, in projects involving the Internet, there is a great deal of demand for front-end data communication, and cross-domain communication is often required.

[0004] Currently, there are two main methods for cross-domain or cross-window page communication: The first method is to use the `postMessage` method. The core of the `postMessage` method is that page B listens for messages triggered by page A. When page A performs a POST operation, page B's listener is triggered in real time, achieving cross-domain communication. However, the `postMessage` method requires that page A and page B exist within the same window. That is, while `postMessage` can achieve communication between items within the same window, it cannot achieve cross-window communication.

[0005] The second method uses WebSockets, a browser API. WebSockets aims to provide full-duplex, bidirectional communication over a single persistent connection (the same-origin policy does not apply to WebSockets). WebSockets initiate a connection by creating a WebSocket in JavaScript and then sending an HTTP request to the browser. Upon receiving a server response, the established connection is upgraded from HTTP to WebSocket. It only works correctly on servers that support the WebSocket protocol. While using sockets allows for real-time communication across tabs and domains, it heavily relies on backend services and cannot solve cross-window, cross-domain real-time communication issues solely from the frontend. Relying on backend-based cross-domain communication has three main drawbacks: First, it has high requirements for the hardware specifications of the backend server, which will increase the purchase and maintenance costs of the backend server. Second, the backend server stores a large amount of data, resulting in a heavy load. This not only makes it time-consuming to retrieve data and implement communication, but it is also limited by the current load of the server and will occupy the server, causing the server to reduce the execution of other tasks. Third, relying on the backend server for communication actually achieves the connection between multiple separate pages. When the backend server or any of the multiple pages malfunctions, or when the connection process is affected by the transmission channel or other factors, the communication connection or interaction process cannot be completed; it has significant limitations.

[0006] Therefore, there is an urgent need for a method that can achieve cross-domain and cross-window information interaction solely based on the front end. Summary of the Invention

[0007] To overcome the drawbacks of relying on server-side cross-domain communication, such as high server requirements, high cost, and long communication time, this application provides a browser-based cross-domain information interaction method, apparatus, and device based on the front end. This method achieves low-cost, high-real-time, and low-limitation cross-domain window information interaction on the same or different pages, based solely on the front end.

[0008] Firstly, this application provides a front-end-based browser cross-domain information interaction method, employing the following technical solution: In response to a subscription operation from a first window page to a second window page, a subscription identifier for the first window page is generated; wherein, the subscription identifier of the first window page is used to represent the subscription relationship between the first window page and the second window page; The first window page calls the message subscription and publishing plugin to pass the subscription mapping information of the first window page, and stores the subscription mapping information of the first window page in the message mapping pool; wherein, the subscription mapping information of the first window page includes: the subscription identifier of the first window page, the communication port of the first window page, the tab data of the first window page, and the callback function of the first window page; In response to the publish operation of the subscribed message on the second window page, the message subscription and publish plugin is invoked to deliver the subscribed message; The subscription message will be broadcast to the first window page according to the subscription mapping information stored in the message mapping pool.

[0009] By adopting the above technical solution, information interaction between different windows is achieved through a message subscription and publish model, realizing loose coupling. Even if one subscribed window cannot communicate, it does not affect the information interaction of other windows, resulting in low limitations. Even in the event of a network outage or other server connectivity issues, cross-domain communication between windows can still be achieved, making its application scenarios unrestricted and highly reliable. Simultaneously, it overcomes the drawbacks of relying on server communication, such as high server requirements, high server purchase costs, and long communication times due to long background server data retrieval times, achieving low-cost, high-efficiency, server-free real-time cross-domain communication. The subscription identifier, communication port, tab data, and callback function of the first window page are stored as subscription mapping information in the message mapping pool of the background layer. This not only allows the front-end to quickly query the various window pages subscribed to the published message based on the subscription identifier after the message publisher publishes the message, but also determines the tab data, communication port, and callback function of each window page subscribed to the published message based on the subscription mapping information of each window page. This facilitates the real-time broadcasting of subscribed messages by calling the callback function, enabling information interaction between multiple cross-domain and cross-page windows and improving the efficiency of interactive communication.

[0010] Furthermore, the first window page subscribes to the second window page by calling a JavaScript object.

[0011] Furthermore, the JavaScript objects are XPCNativeWrapper and wrappedJSObject.

[0012] Furthermore, the message subscription and publishing plugin includes message subscription events and message publishing events; the message subscription event is a regEvent event; and the message publishing event is a fireEvent event.

[0013] By adopting the above technical solutions and utilizing the XPCNativeWrapper and wrappedJSObject methods to penetrate the regEvent and fireEvent message mechanisms, front-end cross-window and cross-domain communication can be achieved without relying on a backend server or backend language.

[0014] Furthermore, broadcasting the subscription message to the first window page according to the subscription mapping information stored in the message mapping pool includes: Upon receiving the subscription message, the system retrieves the first window page for subscribing to the second window page based on the subscription identifier in the subscription mapping information stored in the message mapping pool, and calls the callback function in the subscription mapping information of the first window page to broadcast the subscription message to the first window page.

[0015] By adopting the above technical solutions, the subscriber's identity is determined based on the subscription identifier in the message mapping pool, eliminating the need for a backend server to retrieve identity information and improving the efficiency of subscriber identity determination. Simultaneously, direct communication connections are established based on the communication ports in the subscription mapping information of the window pages stored in the message mapping pool, eliminating the need for a backend server to establish communication connections or transmit messages, thus improving the real-time performance of communication. Furthermore, callback events are executed based on the callback functions of the window pages in the message mapping pool, achieving real-time triggering and quickly sending the subscription message back to the window page that subscribed to the message, improving the efficiency of information interaction. Moreover, communication based on communication ports is not limited by different window tabs, enabling cross-domain and cross-window page communication.

[0016] Furthermore, after retrieving the first window page for the subscribed second window page based on the subscription identifier in the subscription mapping information stored in the message mapping pool, the process further includes: Determine whether the first window page and the second window page are cross-domain windows at different levels of the same page or cross-domain windows of different pages; When the first window page and the second window page are cross-domain windows at different levels of the same page, the communication port of the first window page is determined according to the subscription mapping information of the first window page, a communication connection is established with the first window page according to the communication port of the first window page, and the callback function in the subscription mapping information of the first window page is called to broadcast the subscription message to the current tab data of the second window page.

[0017] Furthermore, when the first window page and the second window page are cross-domain windows of different pages, the communication port and tab data of the first window page are determined according to the subscription mapping information of the first window page. A communication connection is established with the first window page according to the communication port of the first window page, and the callback function in the subscription mapping information of the first window page is called to broadcast the subscription message to the tab data of the first window page.

[0018] By adopting the above technical solutions, cross-domain window pages are further classified into cross-domain windows at different levels within the same page and cross-domain windows across different pages. Different settings are applied to different categories of cross-domain windows, improving the efficiency of information interaction while enabling simultaneous interaction of multiple window pages, regardless of the number of window pages or whether the tabs are the same: When the first window page and the second window page are cross-domain windows of different levels within the same page, the callback function is directly executed to send the subscription message to the current tab of the second page, thus completing the communication process. This further improves communication efficiency compared to cross-domain windows across different pages; when the first window page and the second window page... When dealing with cross-domain windows on different pages, the callback function is called to send the subscription message to the tab of the first window page. This can be done directly to the first window page without the involvement of the backend server, improving communication efficiency and real-time performance compared to cross-domain communication that requires the involvement of the backend server. When there are multiple first window pages, and each first window page and the second window page are of different cross-domain types, the subscription mapping information of each window page is called to execute the callback event, broadcasting the subscription message to multiple window pages simultaneously. This is not limited by the number of windows or the different tabs of the window pages, enabling real-time cross-domain communication of different types across multiple window pages.

[0019] Secondly, this application provides a front-end-based browser cross-domain information interaction device, which adopts the following technical solution: A front-end-based browser cross-domain information interaction device, comprising: The message subscription module is used to generate a subscription identifier for the first window page in response to the subscription operation of the first window page to the second window page, wherein the subscription identifier of the first window page is used to represent the subscription relationship between the first window page and the second window page; The message mapping pool construction module is used for the first window page to call the message subscription and publishing plugin to pass the subscription mapping information of the first window page, and to store the subscription mapping information of the first window page in the message mapping pool; wherein, the subscription mapping information of the first window page includes: subscription identifier, communication port of the first window page, tab data of the first window page, and callback function of the first window page; The message publishing module, in response to the publishing operation of the subscribed message on the second window page, calls the message subscription publishing plugin to transmit the subscribed message; The information interaction module is used to broadcast the subscription message to the first window page according to the subscription mapping information stored in the message mapping pool.

[0020] By adopting the above technical solutions and utilizing a message subscription and publish model for information interaction between different windows, loose coupling is achieved. Even if one subscribed window cannot communicate, it does not affect the information interaction of other windows, resulting in low limitations. Even in the event of a network outage or inability to connect to other servers, cross-domain communication between windows can still be achieved, making its application scenarios unrestricted and highly reliable. Simultaneously, it overcomes the drawbacks of relying on server communication, such as high server requirements, high costs, and long communication times, achieving low-cost, high-efficiency, server-free real-time cross-domain communication.

[0021] Thirdly, this application provides an electronic device that adopts the following technical solution: An electronic device includes a processor coupled to a memory; The memory stores a browser-based cross-domain information interaction method that can be loaded by a processor and executed according to any one of the first aspects.

[0022] Fourthly, this application provides a computer-readable storage medium, which adopts the following technical solution: A computer-readable storage medium includes a computer program or instructions that, when executed on a computer, cause the computer to perform the front-end-based browser cross-domain information interaction method according to any one of the first aspects. Attached Figure Description

[0023] Figure 1 This is a flowchart illustrating the browser cross-domain information interaction method based on the front end provided in this application embodiment.

[0024] Figure 2 This is an interactive diagram illustrating a front-end-based browser cross-domain information interaction method for cross-domain windows of different pages provided in this application embodiment.

[0025] Figure 3 This is an interactive diagram illustrating a front-end-based browser cross-domain information interaction method for cross-domain windows at different levels on the same page, as provided in an embodiment of this application.

[0026] Figure 4 This is a structural block diagram of a front-end-based browser cross-domain information interaction device provided in an embodiment of this application.

[0027] Figure 5 This is a structural block diagram of the electronic device provided in the embodiments of this application. Detailed Implementation

[0028] This specific embodiment is merely an explanation of this application and is not intended to limit it. After reading this specification, those skilled in the art can make modifications to this embodiment without contributing any inventive step, but such modifications are protected by patent law as long as they fall within the scope of the claims of this application.

[0029] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0030] Furthermore, the term "and / or" in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this article, unless otherwise specified, generally indicates that the preceding and following related objects have an "or" relationship.

[0031] The embodiments of this application will now be described in further detail with reference to the accompanying drawings.

[0032] This application provides a front-end-based browser cross-domain information interaction method. This front-end-based browser cross-domain information interaction method can be executed by an electronic device, which can be a server or a terminal device. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal device can be a smartphone, tablet computer, desktop computer, etc., but is not limited to these.

[0033] like Figure 1 As shown, the browser cross-domain information interaction method based on the front end in this embodiment includes (steps S101 to S104): S101, in response to the subscription operation of the first window page to the second window page, a subscription identifier of the first window page is generated; wherein, the subscription identifier of the first window page is used to represent the subscription relationship between the first window page and the second window page.

[0034] In this embodiment, a window page refers to a browser tab; the first window page and the second window page are used to represent different tabs of the same browser, and there is no order relationship between them; the first window page subscribes to the second window page with which it wishes to interact with information, and the first window page can subscribe to one second window page or multiple different second window pages; and the subscribed second window page can also be subscribed to by multiple other first window pages at the same time.

[0035] In this embodiment, the first window page and its subscribed second window page are cross-domain window pages. Specifically, cross-domain window pages can be cross-domain window pages with the same domain but different ports or the same domain but different protocols; they can be cross-domain window pages with the same main domain but different subdomains or the same domain but different second-level domains; they can also be cross-domain window pages with different domains; they can also be cross-domain window pages with the same domain but different domain name representations; and they can also be nested cross-domain window pages at different levels of the same window page.

[0036] For example, if the URL of the first window page is http: / / www.a.com:8000 / a.js and the URL of the second window page is http: / / www.a.com / b.js, then the first and second window pages are cross-domain windows on the same domain but different ports. Similarly, if the URL of the first window page is http: / / www.a.com / a.js and the URL of the second window page is https: / / www.a.com / b.js, then the first and second window pages are cross-domain windows on the same domain but different protocols. If the URL of the first window page is http: / / www.a.com / a.js and the URL of the second window page is http: / / script.a.com / b.js, then the first and second window pages are cross-domain windows on the same main domain but different subdomains. Finally, if the URL of the first window page is http: / / www.a.com / a.js and the URL of the second window page is http: / / ... In the first case, the first window page and the second window page are cross-domain window pages with the same domain name but different subdomains. In the second case, the URL of the first window page is http: / / www.cnblogs.com / a.js, and the URL of the second window page is http: / / www.a.com / b.js, indicating that the first and second window pages are cross-domain window pages with different domain names. In the third case, the URL of the first window page is http: / / www.a.com / a.js, and the URL of the second window page is http: / / 70.32.92.74 / b.js, where 70.32.92.74 is the IP address corresponding to www.a.com. In this case, the first and second window pages are cross-domain browser windows with the same domain name but different domain name representations. In the fourth case, the first window page is a Baidu browser page, and the second window page is an embedded Gaode Map or other program page within the Baidu page. In this case, the first and second window pages are nested cross-domain window pages at different levels within the same page.

[0037] In this embodiment, if a first window page subscribes to multiple second window pages, the subscribed second window pages can be windows within the same domain, windows across domains, or multi-level nested windows. For example, window page A subscribes to window pages B, C, and D, where window page A and window page B are cross-domain window pages with the same domain but different ports or the same domain but different protocols; window page A and window page C are nested cross-domain windows (i.e., a parent page and a child page nested within the parent page); window page A and window page D are cross-domain window pages with different domains, and there are no other restrictions on the domains of window pages B, C, and D.

[0038] In this embodiment, the first window page calls a JavaScript object to complete the subscription operation of the second window page. Specifically, the JavaScript object can be called through front-end code or by generating a front-end control.

[0039] In this embodiment, the JavaScript objects are XPCNativeWrapper and wrappedJSObject from the Firefox browser's content layer. XPCNativeWrapper is used to create a secure wrapper, ensuring that the object's "native" methods / properties are called (rather than methods overridden by the webpage), thus protecting Chrome code that uses the content object. wrappedJSObject is used to access the JavaScript object hidden by the wrapper. This embodiment utilizes XPCNativeWrapper and wrappedJSObject to penetrate the regEvent and fireEvent message mechanism methods, one responsible for subscription and the other for sending.

[0040] In this embodiment, after the first window page subscribes to the second window page, a subscription identifier for the first window page, which includes both the first and second window pages, is generated. This subscription identifier represents the subscription association between the first and second window pages.

[0041] S102, the first window page calls the message subscription and publishing plugin to pass the subscription mapping information of the first window page, and stores the subscription mapping information of the first window page in the message mapping pool; wherein the subscription mapping information of the first window page includes: the subscription identifier of the first window page, the communication port of the first window page, the tab data of the first window page, and the callback function of the first window page.

[0042] In this embodiment, the message subscription and publishing plugin includes message subscription events and message publishing events; the message subscription event is a regEvent event; and the message publishing event is a fireEvent event.

[0043] In this embodiment, the message subscription event, i.e., the regEvent, of the message subscription and publishing plugin is invoked to subscribe to messages.

[0044] In this embodiment, the message mapping pool is used to store the subscription mapping information of all window pages in the form of strings.

[0045] In this embodiment, step S102 specifically includes: after the first window page completes the subscription operation of the second window page, it calls the Firefox browser's regEvent event to pass the subscription mapping information of the first window page to the Firefox browser's background layer; the background layer converts the received subscription mapping information into a map object and stores it in the message mapping pool.

[0046] S103, in response to the publishing operation of the subscribed message on the second window page, calls the message subscription publishing plugin to deliver the subscribed message.

[0047] In this embodiment, the message publishing event of the message subscription publishing plugin, i.e., the browser's fireEvent, is invoked to publish the message.

[0048] In this embodiment, step S103 specifically includes: the second window page, which is subscribed to by the first window page, publishes a subscription message, and the second window page sends the published subscription message to the background layer of Firefox browser through the fireEvent event of Firefox browser.

[0049] S104, broadcast the subscription message to the first window page according to the subscription mapping information stored in the message mapping pool.

[0050] In this embodiment, the background layer receives the subscription message and queries the first window page of the subscribed second window page based on the subscription identifier in the subscription mapping information stored in the message mapping pool; it then determines whether the first window page and the second window page are cross-domain windows at different levels of the same page or cross-domain windows of different pages. When the first window page and the second window page are cross-domain windows at different levels of the same page, the communication port of the first window page is determined according to the subscription mapping information of the first window page. A communication connection is established with the first window page according to the communication port of the first window page, and the callback function in the subscription mapping information of the first window page is called to broadcast the subscription message to the determined tab data of the first window page. When the first window page and the second window page are cross-domain windows of different pages, the communication port and tab data of the first window page are determined based on the subscription mapping information of the first window page. A communication connection is established with the first window page based on the communication port, and the callback function in the subscription mapping information of the first window page is called to broadcast the subscription message to the current tab data of the second window page.

[0051] In this embodiment, step S104 specifically includes: First, the Firefox browser's background layer receives the subscription message sent by the subscribed second window page. The background layer determines the information of the first window page that subscribes to the second window page based on all the subscription mapping information stored in the message mapping pool (there may be one or more first window pages). That is, it determines the information of all subscribers who subscribe to the message based on the subscription identifier in the subscription mapping information and the information of the message publisher.

[0052] Secondly, the background layer determines whether the message subscriber (the first window page) and the message publisher (the second window page) are cross-domain windows of different pages or cross-domain windows of the same page but at different levels. Cross-domain windows of different pages are two different tabs in the browser; cross-domain windows of the same page but at different levels are other pages embedded in the same window page (for example, the browser's Baidu page embeds Gaode Map or other program pages).

[0053] If the first and second windows are cross-domain windows from different pages, the browser's background layer establishes communication with the first window page based on the tab data and communication port information stored in the message map pool. The `regEvent` callback function of the first window page stored in the message map pool is triggered, executing the callback event and broadcasting the subscribed messages from the second window page to the first window page, thus achieving cross-domain window communication between different pages. Figure 2 As shown.

[0054] If the first and second windows are cross-domain windows on the same page but at different levels, their main tab data is identical. In this case, the `regEvent` callback function of the first window page stored in the message mapping pool is triggered, executing the callback event and directly sending the subscription message published by the second window page to its current tab. Because the second and first windows are at different levels of the same page, the second window page sends the subscription message to its current tab, effectively sending the message to the first window page, thus achieving cross-domain window communication across different levels on the same page. Figure 3 As shown.

[0055] If there are multiple first-window pages, and there are cross-domain windows between the multiple first-window pages and the second-window pages, as well as cross-domain windows at different levels of the same page, then the information of different window pages is determined for different cross-domain types, and the callback function is executed respectively. The subscription message published by the second-window page is broadcast to multiple first-window pages at the same time, realizing multi-page, real-time, cross-domain communication.

[0056] In this embodiment, whether it's a cross-domain window on the same page or a cross-domain window on different pages, the corresponding regEvent can be triggered by passing a subscription identifier through fireEvent, and data transmission is also supported. Compared to the traditional postMessage method where page B listens for post operations from page A to achieve cross-domain communication within the same window page, this application can achieve real-time triggering of regEvent and data transmission even between different window pages by passing a subscription identifier through fireEvent, thus realizing cross-domain communication between different window pages.

[0057] According to the embodiments disclosed in this application, the following technical effects are achieved: This application adopts the publish / subscribe message pattern. In software architecture, publish / subscribe is a messaging paradigm where the message sender (publisher) does not directly send the message to a specific receiver (subscriber), but broadcasts it through a message channel so that all subscribers to the message topic can consume it. The biggest feature of the publish / subscriber pattern is that it achieves loose coupling, decoupling numerous windows that need to communicate, allowing each window to be managed independently. Furthermore, even if some windows become unconnected, it will not affect the communication of other windows. The message delivery infrastructure of the publish / subscriber pattern is responsible for broadcasting messages to each subscriber; that is, publishers can publish messages and subscribers can receive them, rather than finding a way to connect two separate systems.

[0058] This application requires no backend server involvement; it achieves cross-domain window information or data transfer solely by utilizing relevant information stored in the frontend's background layer and executing callback events via browser plugins. Other current methods for cross-domain window communication, such as WebSockets, require servers supporting specific WebSocket protocols and cannot achieve cross-domain communication solely dependent on the frontend. This application, however, enables cross-domain communication from a purely frontend perspective.

[0059] When this application is combined with current technologies such as WebSockets in scenarios where the network is down or other servers are unreachable, this application can still achieve cross-domain communication between different window pages or different levels of the same window page. In contrast, technologies like WebSockets require server support, but if the server is unresponsive, communication fails. Furthermore, cross-domain communication technologies like WebSockets have high hardware requirements for the backend server, increasing the cost of cross-domain communication. The large amount of data stored on the backend server also leads to long response times and communication latency. This application, however, requires no backend server involvement throughout the entire process. It eliminates the need to purchase an additional backend server, achieving low-cost cross-domain communication with fewer limitations. Moreover, the entire communication process is completed on the frontend, relying on a message mapping pool for message broadcasting, resulting in high real-time communication. This overcomes the shortcomings of current cross-domain communication technologies, such as high cost, high hardware requirements, high limitations, and latency.

[0060] This application provides a novel front-end communication method that supports real-time communication across the same domain, cross domains, the same window, cross-window pages, and multi-level nested cross domains. It does not rely on any backend application services and truly achieves real-time communication across domains and cross-window pages in the pure front-end. It also features low cost, high real-time communication performance, and low limitation.

[0061] Applying the front-end-based browser cross-domain information interaction method of this embodiment to cross-domain communication in actual website projects has yielded good feedback results. It has high flexibility and integration, and provides great convenience for cross-tab communication within website projects. Applying the front-end-based browser cross-domain information interaction method of this embodiment to projects that require front-end communication and cooperation with third-party companies can not only provide a quick communication entry point and method, but also greatly improve the efficiency of the connection.

[0062] In another embodiment, this application can also be applied to communication between windows in the same domain, such as communication between windows in the same domain at the same level on the same page. Specific steps include: a first window page subscribing to a second window page's subscription operation, generating a subscription identifier for the first window page; wherein the subscription identifier represents the subscription relationship between the first and second window pages; the first window page calling a message subscription publishing plugin to transmit its subscription mapping information, and storing the subscription mapping information in a message mapping pool; wherein the subscription mapping information of the first window page includes the first window page's subscription identifier, the first window page's communication port, the first window page's tab data, and the first window page's callback function; the second window page publishing a subscription message and calling the message subscription publishing plugin to transmit the subscription message; and directly broadcasting the transmitted subscription message to the current tab of the second window page, thus achieving communication between windows at the same level on the same page.

[0063] Figure 4 A structural block diagram of a front-end-based browser cross-domain information interaction device 200 provided in this application embodiment; as shown... Figure 4 As shown, the front-end-based browser cross-domain information interaction device 200 mainly includes: The message subscription module 201 is used to generate a subscription identifier for the first window page in response to the subscription operation of the first window page to the second window page. The subscription identifier of the first window page is used to represent the subscription relationship between the first window page and the second window page. The message mapping pool construction module 202 is used for the first window page to call the message subscription and publishing plugin to pass the subscription mapping information of the first window page, and to store the subscription mapping information of the first window page in the message mapping pool; wherein, the subscription mapping information of the first window page includes: subscription identifier, communication port of the first window page, tab data of the first window page, and callback function of the first window page; The message publishing module 203 is used to respond to the publishing operation of the subscribed message on the second window page and call the message subscription publishing plugin to deliver the subscribed message; The information interaction module 204 is used to broadcast the subscription message to the first window page according to the subscription mapping information stored in the message mapping pool.

[0064] The functional modules in the embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part. If the function is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of a front-end-based browser cross-domain information interaction method according to various embodiments of this application.

[0065] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described device and module can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0066] Figure 5 This is a structural block diagram of an electronic device 300 provided in an embodiment of this application. (See diagram below.) Figure 5As shown, the electronic device 300 includes a memory 301, a processor 302, and a communication bus 303; the memory 301 and the processor 302 are connected via the communication bus 303. The memory 301 stores a browser-based cross-domain information interaction method, as provided in the above embodiment, which can be loaded and executed by the processor 302.

[0067] The memory 301 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 301 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for at least one function, and instructions for implementing the front-end-based browser cross-domain information interaction method provided in the above embodiments. The data storage area may store data involved in the front-end-based browser cross-domain information interaction method provided in the above embodiments.

[0068] Processor 302 may include one or more processing cores. Processor 302 executes instructions, programs, code sets, or instruction sets stored in memory 301, and calls data stored in memory 301 to perform various functions and process data as described in this application. Processor 302 may be at least one of the following: Application Specific Integrated Circuit (ASIC), Digital Signal Processor (DSP), Digital Signal Processing Device (DSPD), Programmable Logic Device (PLD), Field Programmable Gate Array (FPGA), Central Processing Unit (CPU), Controller, Microcontroller, and Microprocessor. It is understood that, for different devices, the electronic devices used to implement the functions of processor 302 may also be other types, and this application embodiment does not specifically limit the specific devices used.

[0069] The communication bus 303 may include a path for transmitting information between the aforementioned components. The communication bus 303 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus 303 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5The symbol is represented by a single double arrow, but this does not mean that there is only one bus or one type of bus.

[0070] In another aspect, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the aforementioned front-end-based browser cross-domain information interaction method. The computer-readable storage medium can be a tangible device that holds and stores instructions used by an instruction execution device. The computer-readable storage medium can be, but is not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any combination thereof. Specifically, the computer-readable storage medium can be a portable computer disk, a hard disk, a USB flash drive, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), staging random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital multifunction disc (DVD), memory stick, floppy disk, optical disk, magnetic disk, mechanical encoding device, or any combination thereof.

[0071] The terms “comprising,” “including,” or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0072] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the foregoing application concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions claimed in this application.

Claims

1. A front-end-based browser cross-domain information interaction method, characterized in that, include: In response to a subscription operation from a first window page to a second window page, a subscription identifier for the first window page is generated; wherein, the subscription identifier of the first window page is used to represent the subscription relationship between the first window page and the second window page; The first window page calls the message subscription and publishing plugin to pass the subscription mapping information of the first window page, and stores the subscription mapping information of the first window page in the message mapping pool; wherein, the subscription mapping information of the first window page includes: the subscription identifier of the first window page, the communication port of the first window page, the tab data of the first window page, and the callback function of the first window page; In response to the publish operation of the subscribed message on the second window page, the message subscription and publish plugin is invoked to deliver the subscribed message; The subscription message will be broadcast to the first window page according to the subscription mapping information stored in the message mapping pool. The step of broadcasting the subscription message to the first window page according to the subscription mapping information stored in the message mapping pool includes: Upon receiving the subscription message, the system retrieves the first window page for which the second window page is subscribed based on the subscription identifier in the subscription mapping information stored in the message mapping pool, and then calls the callback function in the subscription mapping information of the first window page to broadcast the subscription message to the first window page. After retrieving the first window page of the subscribed second window page based on the subscription identifier in the subscription mapping information stored in the message mapping pool, the process further includes: Determine whether the first window page and the second window page are cross-domain windows at different levels of the same page or cross-domain windows of different pages; When the first window page and the second window page are cross-domain windows at different levels of the same page, the communication port of the first window page is determined based on the subscription mapping information of the first window page. A communication connection is established with the first window page based on the communication port of the first window page, and the callback function in the subscription mapping information of the first window page is called to broadcast the subscription message to the current tab data of the second window page. When the first window page and the second window page are cross-domain windows of different pages, the communication port and tab data of the first window page are determined according to the subscription mapping information of the first window page. A communication connection is established with the first window page according to the communication port of the first window page, and the callback function in the subscription mapping information of the first window page is called to broadcast the subscription message to the tab data of the first window page.

2. The method according to claim 1, characterized in that, The first window page subscribes to the second window page by calling a JavaScript object.

3. The method according to claim 2, characterized in that, The JavaScript objects are XPCNativeWrapper and wrappedJSObject.

4. The method according to claim 1, characterized in that, The message subscription and publishing plugin includes message subscription events and message publishing events; the message subscription event is a regEvent event; the message publishing event is a fireEvent event.

5. An electronic device, characterized in that, Includes a processor, which is coupled to a memory; The processor is configured to execute a computer program stored in the memory, so that the electronic device performs the front-end-based browser cross-domain information interaction method as described in any one of claims 1 to 4.

6. A computer-readable storage medium, characterized in that, It includes a computer program or instructions that, when run on a computer, cause the computer to perform the front-end-based browser cross-domain information interaction method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Data processing method and device, equipment, medium and program product

    CN116304411A