Disclosure of Invention
The embodiment of the invention aims to provide an information transmission method, an information transmission device and a browser, which can reduce the probability of errors in information transmission between pages.
In order to achieve the above object, an embodiment of the present invention discloses an information transmission method, including:
after jumping to a target page under the same domain name from a current page, receiving an instruction for transmitting target information of the current page to the target page, wherein the target information is as follows: the information which can be transmitted to the target page in the current page;
judging whether a preset public page contains the target information or not;
if so, the target information contained in the public page is transmitted to the target page.
Optionally, after the transmitting the target information contained in the public page to the target page, the method further includes:
and rendering the target page according to the target information.
Optionally, the method further includes:
and when the public page is judged not to contain the target information, writing the target information into the public page, and then executing the step of transmitting the target information contained in the public page to the target page.
Optionally, the step of transferring the target information contained in the public page to the target page includes:
judging whether first information is consistent with the target information contained in the public page, wherein the first information is as follows: the information which needs to be transmitted to the target page currently in the current page;
if so, transmitting the target information contained in the public page to the target page;
otherwise, after the target information contained in the public page is replaced by the first information, the target information contained in the public page is transmitted to the target page.
Optionally, the method further includes:
storing the target information contained in the public page in a local storage of the public page;
before the step of judging whether the target information is stored in the preset public page, the method further includes:
and loading the target information stored in the local storage into the public page.
Optionally, the method further includes:
and deleting the target information stored in the local storage.
In order to achieve the above object, an embodiment of the present invention further discloses an information transmission apparatus, including:
a receiving module, configured to receive, after jumping from a current page to a target page under the same domain name, an instruction for transferring target information of the current page to the target page, where the target information is: the information which can be transmitted to the target page in the current page;
the judging module is used for judging whether a preset public page contains the target information or not; if yes, triggering a transmission module;
the transfer module is configured to transfer the target information included in the public page to the target page.
Optionally, the apparatus further comprises:
and the rendering module is used for rendering the target page according to the target information after the target information contained in the public page is transmitted to the target page by the transmission module.
Optionally, the apparatus further comprises:
and the writing module is used for writing the target information into the public page and triggering the transfer module when the judging module judges that the public page does not contain the target information.
Optionally, the transfer module includes:
a determining submodule, configured to determine whether first information is consistent with the target information included in the public page, where the first information is: the information which needs to be transmitted to the target page currently in the current page; if yes, triggering the transmission submodule, otherwise, triggering the replacement transmission submodule;
the delivery sub-module is configured to deliver the target information included in the public page to the target page when the judgment sub-module judges that the first information is consistent with the target information included in the public page;
the replacement transmission sub-module is configured to, when the judgment sub-module judges that the first information is consistent with the target information included in the public page, replace the target information included in the public page with the first information, and transmit the target information included in the public page to the target page.
Optionally, the apparatus further comprises:
the storage module is used for storing the target information contained in the public page in a local storage of the public page;
and the loading module is used for loading the target information stored in the local storage into the public page before the judging module judges whether the target information is stored in the preset public page.
Optionally, the apparatus further comprises:
and the deleting module is used for deleting the target information stored in the local storage.
In order to achieve the above object, an embodiment of the present invention further discloses a browser, where the browser is a browser that applies any one of the above information transfer devices.
As can be seen from the above, in the solution provided in the embodiment of the present invention, after jumping from the current page to the target page under the same domain name, an instruction for transferring the target information of the current page to the target page is received, whether the target information is stored in a preset public page is determined, and if so, the target information stored in the public page is transferred to the target page.
Therefore, by applying the scheme provided by the embodiment of the invention, the target information of the information which can be transmitted to the target page by the current page can be acquired from the preset public page after the jump between the pages is carried out, and the target information does not need to be acquired from the URL link of the target page, so that the condition of missing transmission or wrong transmission during information transmission between the pages is avoided, and the error probability during information transmission is reduced.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
First, technical terms related to the embodiments of the present invention will be briefly described.
Local storage (localStorage) is an object for storing local data based on a browser of HTML5 technology, and localStorage has the following advantages: large capacity, easy use, strong, native support.
The postMessage is a commonly used function in the Windows API (Application Programming Interface) for placing a message in a message queue. The postMessage method in the HTML5 technology can realize cross-document message transmission, allow scripts from different sources to perform limited communication in an asynchronous mode, and realize cross-text file, multi-window and cross-domain message transmission.
In order to solve the problem of the prior art, embodiments of the present invention provide an information transfer method, an information transfer device, and a browser. First, an information delivery method provided by an embodiment of the present invention is described in detail below.
It should be noted that the information transmission method and apparatus provided in the embodiment of the present invention are preferably applicable to browsers, for example, an IE kernel-based browser and a Chrome kernel-based browser, and certainly are also applicable to other types of browsers, which is not limited in the embodiment of the present invention.
Fig. 2 is a first flowchart of an information delivery method according to an embodiment of the present invention, where the method includes:
s201, after jumping from the current page to the target page under the same domain name, receiving an instruction of transmitting the target information of the current page to the target page.
Wherein, the target information is: information in the current page that can be passed to the target page. For example, the information in the current page that can be passed to the target page may include: the identification information of the user in the current page, the identification information of the commodity in the current page, and the like.
It can be understood that different pages under the same domain name have a certain correlation, for example, a user clicks a jump link in a current page and jumps to a target page corresponding to the jump link under the same domain name, and the content in the target page has a correlation with the content in the current page, at this time, in order to ensure the continuity of information, it is necessary to transfer the information related to the target page in the current page to the target page, so that the target page performs page rendering according to the related information, and responds to other operations of the user on the target page according to the related information.
S202, judging whether a preset public page contains target information or not; if so, S203 is executed.
It should be noted that, it is reasonable that the public page may be a page preset by the browser in the domain name where the current page is located, or may be a page automatically added to the domain name by the browser when the user accesses the web page corresponding to the domain name for the first time, and the like, and the embodiment of the present invention does not limit this.
S203, transmitting the target information contained in the public page to the target page.
Specifically, the step of transferring the target information contained in the public page to the target page may include:
judging whether the first information is consistent with target information contained in the public page, wherein the first information is as follows: the information which needs to be transmitted to the target page currently in the current page;
if so, transmitting the target information contained in the public page to the target page;
otherwise, after the target information contained in the public page is replaced by the first information, the target information contained in the public page is transmitted to the target page.
It can be understood that, in practical applications, a situation may occur where information that can be transferred to a target page in a current page changes, for example: when different users jump from the current page to the target page, the identification information of the users transmitted to the target page by the current page is different; for another example: after the current page is maintained or updated, the target information which can be transmitted to the target page by the current page is changed. Therefore, it is also necessary to determine whether the information that needs to be currently transferred to the target page in the current page is consistent with the target information included in the common page. If the information is inconsistent with the first information, the target information contained in the public page is required to be replaced by the first information, and then the target information contained in the public page is transmitted to the target page, so that the correctness of the transmitted information is ensured.
In practical applications, there may be three cases that the first information is inconsistent with the target information contained in the public page: the first information includes information not included in the object information, the object information includes information not included in the first information, and the object information includes information that does not match the first information. At this time, the target information contained in the public page may be replaced with the first information by calling the postMessage method in the HTML5 to add, delete, and change information in the public page.
In practical application, after jumping to a target page, target information in a public page can be read by calling a postMessage method in the HTML5, so that the transfer of the target information is realized.
In a specific implementation manner of the embodiment of the present invention, as shown in fig. 3, on the basis of the embodiment shown in fig. 2, the information delivery method may further include:
s204, when the public page is judged not to contain the target information, the target information is written into the public page, and then the step S203 is executed.
It can be understood that in practical applications, there may be some cases where the common page does not contain the target information that can be transferred to the target page in the current page, for example: the user jumps from the current page to the target page for the first time, or the target information contained in the common page is cleared before jumping from the current page to the target page. Therefore, when it is determined that the target information is not contained in the common page, the target information may be written in the common page and then the target information contained in the common page may be transferred to the target page.
In practical application, target information can be written into a public page by calling a postMessage method in the HTML5, so that cross-domain storage of the target information is realized, that is, information of a current page is stored into the public page.
In order to locally persist target information contained in a common page, on the basis of the embodiments shown in fig. 2 and fig. 3, the information delivery method may further include: and storing the target information contained in the public page in a local storage of the public page.
In this case, before determining whether the target information is stored in the preset public page, the information delivery method may further include: and loading the target information stored in the local storage of the public page into the public page.
In practical application, if the current page stores the wrong information in the local storage of the public page due to bug (bug) of the development function, the wrong information stored in the local storage of the public page needs to be deleted, so that the correct information is stored in the local storage of the public page again, and the wrong information is prevented from being transmitted to the target page. Therefore, on the basis of the embodiments shown in fig. 2 and fig. 3, the information delivery method may further include: and deleting the target information stored in the local storage.
In practical applications, the target information stored in the local storage can be deleted by calling the postMessage method in the HTML 5.
In an embodiment of the present invention, as shown in fig. 4, on the basis of the embodiment shown in fig. 2, after the step S203 transfers the target information contained in the public page to the target page, the information transfer method may further include:
and S205, rendering the target page according to the target information.
It can be understood that, in practical applications, after the target information included in the public page is transmitted to the target page, the target page may perform page rendering by using the target information, for example, after a user clicks a certain commodity in the current page, the user may jump to the target page corresponding to the commodity, the current page needs to transmit the identification information of the commodity to the target page, the target page may request all information of the commodity, such as pictures, characters, and the like, from the back-end server according to the identification information of the commodity, and perform page rendering on the target page based on the commodity information obtained by the request.
It should be emphasized that, in the embodiment of the present invention, the current page may write all the information that can be transferred to the target page in the current page into the common page, and after jumping from the current page to the target page, the target page may directly read the required target information from the common page. Therefore, developers of the current page only need to consider that all information which can be transmitted to the target page by the current page is written into the public page, and do not need to consider the specific content of the information required by the target page; when a developer of the target page maintains the target page, only the specific information required to be acquired from the public page is changed. Therefore, for developers, only the logic of the page and the information which can be provided by the page to other pages need to be considered, communication with the developers of other pages is not needed, the information which is required to be transmitted to other pages by the page is needed, and the communication pressure among the developers is reduced.
For example, as shown in fig. 5, which is a schematic diagram of information transfer between pages in the information transfer method provided by the embodiment of the present invention, page a may store all state machines of the page into a common page, so-called state machine, that is, information of states in which elements in the page are currently located. After jumping from page a to page B, page B may read the required state machine information from the state machine information of page a in the common page, and perform page rendering based on the read information.
As can be seen from the above, in the solution provided in the embodiment of the present invention, after jumping from the current page to the target page under the same domain name, an instruction for transferring the target information of the current page to the target page is received, whether the target information is stored in a preset public page is determined, and if so, the target information stored in the public page is transferred to the target page.
Therefore, by applying the scheme provided by the embodiment of the invention, the target information of the information which can be transmitted to the target page by the current page can be acquired from the preset public page after the jump between the pages is carried out, and the target information does not need to be acquired from the URL link of the target page, so that the condition of missing transmission or wrong transmission during information transmission between the pages is avoided, and the error probability during information transmission is reduced.
It should be noted that, the common page is set in the same domain name of the current page and the target page, and the security mechanism of the browser only allows the pages in the same domain name to be called, for example, the browser only allows the page with the domain name of a.abc.com to call the information of the page with the domain name of b.abc.com, but does not allow the page corresponding to a.abc.com to call the information of the page corresponding to a.def.com, so that it is safe to use the information transfer method provided by the embodiment of the present invention to transfer information between pages in the same domain name. Moreover, as can be seen from the above description, the embodiment of the present invention can be implemented based on the postMessage method and local storage in the HTML5 technology, the implementation principle is simple, and the used code is popular, so that the application is also simple and convenient.
Corresponding to the information transmission method, the embodiment of the invention also provides an information transmission device.
Corresponding to the method embodiment shown in fig. 2, fig. 6 is a first schematic structural diagram of an information delivery apparatus according to an embodiment of the present invention, where the apparatus may include:
a receiving module 601, configured to receive, after jumping from a current page to a target page under the same domain name, an instruction for transferring target information of the current page to the target page, where the target information is: the information which can be transmitted to the target page in the current page;
a determining module 602, configured to determine whether a preset public page includes the target information; if yes, the transmission module 603 is triggered;
the transferring module 603 is configured to transfer the target information included in the public page to the target page.
In practical applications, the transferring module 603 may include:
a determining submodule (not shown in the figure), configured to determine whether first information is consistent with the target information included in the public page, where the first information is: the information which needs to be transmitted to the target page currently in the current page; if yes, triggering a transmission submodule (not shown in the figure), otherwise, triggering a replacement transmission submodule (not shown in the figure);
the delivery sub-module is configured to deliver the target information included in the public page to the target page when the judgment sub-module judges that the first information is consistent with the target information included in the public page;
the replacement transmission sub-module is configured to, when the judgment sub-module judges that the first information is consistent with the target information included in the public page, replace the target information included in the public page with the first information, and transmit the target information included in the public page to the target page.
In practical applications, as shown in the second schematic structural diagram of the message delivery apparatus shown in fig. 7, on the basis of the embodiment shown in fig. 6, the message delivery apparatus may further include:
a writing module 604, configured to write the target information into the public page and then trigger the transferring module 603 when the determining module 602 determines that the public page does not include the target information.
In practical applications, the information delivery apparatus may further include:
a storage module (not shown in the figure) for storing the target information contained in the public page in a local storage of the public page;
a loading module (not shown in the figure), configured to load the target information stored in the local storage into the public page before the determining module 602 determines whether the target information is stored in a preset public page.
In practical applications, the information delivery apparatus may further include:
a deleting module (not shown in the figure) for deleting the target information stored in the local storage.
In practical applications, as shown in the third schematic structural diagram of the message passing apparatus shown in fig. 8, on the basis of the embodiment shown in fig. 6, the message passing apparatus may further include:
a rendering module 605, configured to render the target page according to the target information after the transfer module 603 transfers the target information included in the public page to the target page.
As can be seen from the above, in the solution provided in the embodiment of the present invention, after jumping from the current page to the target page under the same domain name, an instruction for transferring the target information of the current page to the target page is received, whether the target information is stored in a preset public page is determined, and if so, the target information stored in the public page is transferred to the target page.
Therefore, by applying the scheme provided by the embodiment of the invention, the target information of the information which can be transmitted to the target page by the current page can be acquired from the preset public page after the jump between the pages is carried out, and the target information does not need to be acquired from the URL link of the target page, so that the condition of missing transmission or wrong transmission during information transmission between the pages is avoided, and the error probability during information transmission is reduced.
An embodiment of the present invention further provides a browser, where the browser has the same function as the existing browser, and the browser further applies any one of the information delivery apparatuses in fig. 6 to 8, so that the browser provided in the embodiment of the present invention can achieve the same effect as the above fig. 6 to 8, and the specific content of the browser is not described in detail in the embodiment of the present invention, and the same contents refer to the corresponding contents.
For the above device embodiment and browser, since they are basically similar to the method embodiment, the description is simple, and the relevant points can be referred to the partial description of the method embodiment.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. The term "comprising", without further limitation, means that the element so defined is not excluded from the group consisting of additional identical elements in the process, method, article, or apparatus that comprises the element.
Those skilled in the art will appreciate that all or part of the steps in the above method embodiments may be implemented by a program to instruct relevant hardware to perform the steps, and the program may be stored in a computer-readable storage medium, which is referred to herein as a storage medium, such as: ROM/RAM, magnetic disk, optical disk, etc.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.