[go: up one dir, main page]

CN112162871A - Method, device and storage medium for data exchange between applet and webview - Google Patents

Method, device and storage medium for data exchange between applet and webview Download PDF

Info

Publication number
CN112162871A
CN112162871A CN202011023595.4A CN202011023595A CN112162871A CN 112162871 A CN112162871 A CN 112162871A CN 202011023595 A CN202011023595 A CN 202011023595A CN 112162871 A CN112162871 A CN 112162871A
Authority
CN
China
Prior art keywords
applet
webview
data
page
link
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011023595.4A
Other languages
Chinese (zh)
Inventor
陈虬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tongcheng Network Technology Co Ltd
Original Assignee
Tongcheng Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tongcheng Network Technology Co Ltd filed Critical Tongcheng Network Technology Co Ltd
Priority to CN202011023595.4A priority Critical patent/CN112162871A/en
Publication of CN112162871A publication Critical patent/CN112162871A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/543User-generated data transfer, e.g. clipboards, dynamic data exchange [DDE], object linking and embedding [OLE]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/955Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
    • G06F16/9566URL specific, e.g. using aliases, detecting broken or misspelled links

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Stored Programmes (AREA)

Abstract

The application relates to a method, a device and a storage medium for data exchange between an applet and webview, wherein the method comprises the following steps: when the webview jumps to an applet interface, a current webpage link is added to an applet page address transmission parameter; after the jump, the small program interface receives and stores the transmitted webpage link in the memory; returning the small program page to the webview after the small program page processes the service logic, and returning the returned data and the stored webpage link to the webview when returning to the webview; splicing the returned data and the stored webpage links to serve as new links, and using the new links as the webpage links in the webview; acquiring data returned from the applet; and restoring the new link into the original webpage link. The method and the device have the effect of perfecting a communication system between the small program and the webview.

Description

Method, device and storage medium for data exchange between applet and webview
Technical Field
The present application relates to the field of data exchange, and in particular, to a method, an apparatus, and a storage medium for data exchange between an applet and webview.
Background
Applets provide a development framework and API that helps developers develop native APP in the micro-trusted domain. The webview is a container for bearing a webpage, can be embedded in a mobile terminal, and realizes mixed development of a front end.
With the development of more and more small program developers by the aid of front-end technologies, iterative versions of company products are complicated, rapid iteration causes the size of a small program development kit to increase day by day, capacity exceeds a limit, each online process needs to be approved by a WeChat person, and the approval time is uncontrollable. Part of the function pages need to be cut into webview to solve the capacity problem and part of the issue limitation problem. In the related technology, the applet interface is returned to the webview, so that data cannot be brought in, and the interaction between the applet page and the webview is realized through a postMessage method given by an official party.
For the above related technologies, the inventor thinks that when an official in the related technology realizes interaction between the applet and the webview by using a postMessage method, data transmission to the applet through the webview can be realized only when a message event is triggered at a specific time, but data transmission to the webview by the applet is not supported, and the communication function is not perfect.
Disclosure of Invention
In order to improve a communication system between an applet and a webview, the application provides a method, a device and a storage medium for data exchange between the applet and the webview.
In a first aspect, the present application provides a method for exchanging data between an applet and webview, which adopts the following technical solution:
a method of applet exchange with webview data comprising the steps of:
when the webview jumps to an applet interface, a current webpage link is added to an applet page address transmission parameter; after the jump, the small program interface receives and stores the transmitted webpage link in the memory;
returning the small program page to the webview after the small program page processes the service logic, and returning the returned data and the stored webpage link to the webview when returning to the webview;
splicing the returned data and the stored webpage links to serve as new links, and using the new links as the webpage links in the webview;
acquiring data returned from the applet;
and restoring the new link into the original webpage link.
By adopting the technical scheme, the data are transmitted to the small program through the webview, and meanwhile, the small program transmits the data back to the webview. When the applet returns, the stored webpage links and returned data are spliced together, wherein the returned data are pictures or characters obtained through the applet, the returned data are spliced with the webpage links, the applet can transmit new links to the webview during returning, and communication between the applet and the webview is improved.
Optionally, when the applet returns to the webview, a fixed method is predefined in the webview, and the parameters are data and web page links received and returned by the object.
By adopting the technical scheme, the predefined fixing method is used for receiving the returned data and the webpage link, and further the data and the webpage link are transmitted when the small program is returned.
Optionally, returning the applet to the webview triggers an onShow lifecycle; in the step of setting the webpage links, the onShow lifecycle takes the returned data as a hash value, and the hash value and the stored webpage links are spliced into a new link.
By adopting the technical scheme, when the applet returns to the webview, the onShow hook is triggered to acquire the returned data and the webpage link, and the returned picture or character is used as a hash value to be spliced with the originally stored webpage link to form a new link. The original webpage link is guaranteed to be positioned when the web browser jumps back to webview through the originally stored webpage link, and the accuracy of the page jump back is improved.
Optionally, a hash event is set in the webview, the hash event monitors that the hash value changes, and the hash value in the new link is taken out, that is, the data returned in the applet is obtained.
By adopting the technical scheme, after the hash value is monitored to be changed, the hash value can be taken out, and the picture or the character returned by the applet is displayed. And finishing the interaction of the applet and the webview.
Optionally, when the new link is restored to the original web page link, executing window.
By adopting the technical scheme, the hash value can be deleted by executing the window.
Optionally, the applet page is closed after the applet page processes the service logic, and the applet page is returned to webview after being closed.
By adopting the technical scheme, the step of returning to the webview is executed to indicate that the small program page has processed the service logic, and the small program page can be returned to the webview and the subsequent data transmission operation is carried out.
Optionally, after the applet page processes the service logic, the applet page is closed after the user clicks a return button of the applet page or the user clicks any position of the applet page.
By adopting the technical scheme, the user clicks the return button or any position of the small program page.
Optionally, after the applet page processes the service logic, the applet page is delayed to be automatically closed.
By adopting the technical scheme, the small program page is closed through delayed automatic closing of the small program page, which indicates that the small program page has processed the service logic and can be subsequently operated.
In a second aspect, the present application provides an apparatus for exchanging an applet with webview data, which adopts the following technical solution:
an apparatus for applet exchange with webview data comprising a memory and a processor, the memory having stored thereon a computer program capable of being loaded by the processor and of carrying out any one of the methods described above.
By adopting the technical scheme, the method has the characteristics that the data can be returned to the webview by the applet, and the communication between the applet and the webview is realized.
In a third aspect, the present application provides a storage medium for exchanging an applet and webview data, which adopts the following technical solution:
a storage medium for applet exchange with webview data, storing a computer program capable of being loaded by a processor and executing any one of the methods described above.
By adopting the technical scheme, the corresponding program can be stored, and the method has the characteristics of supporting the applet to transmit data back to the webview and realizing communication between the applet and the webview.
In summary, the present application includes at least one of the following beneficial technical effects:
1. the method comprises the steps of acquiring returned data and restoring a webpage by transmitting webpage connection, returning an applet, setting a webpage link, transmitting the data to the applet through the webview, and simultaneously transmitting the data returned by the applet to the webview;
2. restoring the webpage by executing window.
Drawings
Fig. 1 is a block diagram showing the structure of the method of exchanging the applet with webview data disclosed in examples 1 and 2.
Detailed Description
The present application is described in further detail below with reference to fig. 1.
The embodiment of the application discloses a method for exchanging an applet and webview data.
Example one
Referring to FIG. 1, a method of applet exchange with webview data comprising the steps of:
s1, when the webview jumps to the small program interface, adding a current webpage link on the address transmission parameter of the small program page; and after the jump, the small program interface receives and stores the transmitted webpage link in the memory.
And S2, closing the small program page after the small program page finishes processing the service logic, returning to the webview after the small program page is closed, and returning the returned data and the stored webpage link to the webview together when the small program page is returned to the webview.
The business logic of the applet page can be photographing or inputting characters and the like according to different operation requirements, and the photos or the characters are used as returned data.
After the small program page processes the service logic, the user clicks a return button of the small program page or clicks any position of the small program page, and then the small program page is closed; or after the small program page processes the service logic, the small program page is delayed to be automatically closed.
A fixed method setH5Data is predefined in webview, and parameters are Data received and returned by an object and web page links and are stored in a memory. When the applet page returns to webview, the fixed method setH5Data is called first, and the returned Data and the webpage link are transmitted into the fixed method setH5Data and stored in the memory.
And S3, splicing the returned data and the stored webpage links to serve as new links, and using the new links as the webpage links in the webview.
Returning the applet to the webview triggers an onShow lifecycle hook, which is the api of the applet page. And in the onShow life cycle, the returned data is used as a hash value, the hash value and the stored webpage links are spliced into a new link, the new link is the original stored webpage link plus the hash value, and the new link is used as the webpage link in the webview.
And S4, acquiring the data returned from the applet.
And a hash event is set in the webview, the hash event monitors that the hash value changes, and the hash value in the new link is taken out, namely, the data returned in the applet is obtained.
And S5, restoring the new link to the original webpage link.
Restoring the webpage by executing window.
The embodiment of the application also discloses a device for exchanging the small program and webview data. Comprising a memory and a processor, the memory having stored thereon a computer program which can be loaded by the processor and which performs the method as described above.
The embodiment of the application also discloses a storage medium for exchanging the small program and webview data. Which stores a computer program that can be loaded by a processor and executed in a method as described above, the computer readable storage medium comprising, for example: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The above embodiments are preferred embodiments of the present application, and the protection scope of the present application is not limited by the above embodiments, so: all equivalent changes made according to the structure, shape and principle of the present application shall be covered by the protection scope of the present application.

Claims (10)

1.一种小程序与webview数据交换的方法,其特征在于:包括以下步骤:1. a method for small program and webview data exchange, is characterized in that: comprise the following steps: webview跳转至小程序界面时,在小程序页面地址传递参数上追加当前网页链接;跳转后小程序界面接收并保存传递的网页链接在内存中;When the webview jumps to the applet interface, the current webpage link is added to the parameter passed by the applet page address; after the jump, the applet interface receives and saves the passed webpage link in the memory; 小程序页面处理完业务逻辑后返回至webview,在返回至webview时,将回传的数据和保存的网页链接一并回传至webview中;The applet page returns to the webview after processing the business logic. When returning to the webview, the returned data and the saved webpage link are returned to the webview together; 拼接回传的数据和保存的网页链接作为新链接,将新链接作为webview中的网页链接;Splicing the returned data and the saved webpage link as a new link, and using the new link as the webpage link in the webview; 获取从小程序中回传的数据;Get the data returned from the applet; 将新链接还原为原网页链接。Restore the new link to the original web link. 2.根据权利要求1所述的小程序与webview数据交换的方法,其特征在于:小程序返回至webview时,webview中预先定义固定方法,参数为对象接收回传的数据和网页链接。2 . The method for exchanging data between applet and webview according to claim 1 , wherein: when the applet returns to the webview, a fixed method is pre-defined in the webview, and the parameters are the data returned by the object and the web page link. 3 . 3.根据权利要求1所述的小程序与webview数据交换的方法,其特征在于:小程序返回至webview中会触发onShow生命周期;在设置网页链接步骤中,onShow生命周期将回传的数据作为hash值,hash值与保存的网页链接拼接成新链接。3. the method for data exchange between applet and webview according to claim 1, it is characterized in that: applet returns to webview and can trigger onShow life cycle; In setting webpage link step, onShow life cycle uses the data returned as hash value, the hash value is spliced with the saved web page link to form a new link. 4.根据权利要求3所述的小程序与webview数据交换的方法,其特征在于:webview中设置有hashchange事件,hashchange事件监听hash值发生改变,将新链接中的hash值取出,即获得小程序中回传的数据。4. the method for data exchange between applet and webview according to claim 3, it is characterized in that: a hashchange event is provided in the webview, the hashchange event monitors the hash value to change, and the hash value in the new link is taken out, that is, the applet is obtained data sent back. 5.根据权利要求4所述的小程序与webview数据交换的方法,其特征在于:将新链接还原为原网页链接时,执行window.histroy.go(-1),将网页还原去除hash值。5. The method for exchanging data between applet and webview according to claim 4, characterized in that: when restoring the new link to the original web page link, execute window.histroy.go(-1) to restore the web page and remove the hash value. 6.根据权利要求1所述的小程序与webview数据交换的方法,其特征在于:小程序页面处理完业务逻辑后小程序页面关闭,小程序页面关闭后返回至webview。6 . The method for exchanging data between applet and webview according to claim 1 , wherein: the applet page is closed after the applet page has processed the business logic, and the applet page is closed and returns to the webview. 7 . 7.根据权利要求6所述的小程序与webview数据交换的方法,其特征在于:小程序页面处理完业务逻辑后,用户点击小程序页面的返回按钮或用户点击小程序页面的任意位置后,小程序页面关闭。7. The method for exchanging data between applet and webview according to claim 6, characterized in that: after the applet page has processed the business logic, the user clicks the return button of the applet page or after the user clicks any position on the applet page, The applet page is closed. 8.根据权利要求6所述的小程序与webview数据交换的方法,其特征在于:小程序页面处理完业务逻辑后,小程序页面延时自动关闭。8 . The method for exchanging data between applet and webview according to claim 6 , wherein: after the applet page finishes processing the business logic, the applet page is automatically closed after a delay. 9 . 9.一种小程序与webview数据交换的装置,其特征在于:包括存储器和处理器,所述存储器上存储有能够被处理器加载并执行如权利要求1至8中任一种方法的计算机程序。9. A device for exchanging data between applet and webview, characterized in that it comprises a memory and a processor, and the memory is stored with a computer program that can be loaded by the processor and executes the method as claimed in any one of claims 1 to 8 . 10.一种小程序与webview数据交换的存储介质,其特征在于:存储有能够被处理器加载并执行如权利要求1至8中任一种方法的计算机程序。10. A storage medium for exchanging data between applet and webview, characterized in that: a computer program capable of being loaded by a processor and executing the method according to any one of claims 1 to 8 is stored.
CN202011023595.4A 2020-09-25 2020-09-25 Method, device and storage medium for data exchange between applet and webview Pending CN112162871A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011023595.4A CN112162871A (en) 2020-09-25 2020-09-25 Method, device and storage medium for data exchange between applet and webview

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011023595.4A CN112162871A (en) 2020-09-25 2020-09-25 Method, device and storage medium for data exchange between applet and webview

Publications (1)

Publication Number Publication Date
CN112162871A true CN112162871A (en) 2021-01-01

Family

ID=73863855

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011023595.4A Pending CN112162871A (en) 2020-09-25 2020-09-25 Method, device and storage medium for data exchange between applet and webview

Country Status (1)

Country Link
CN (1) CN112162871A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114217866A (en) * 2021-11-08 2022-03-22 阿里健康科技(中国)有限公司 Applet using method and device and electronic equipment
CN114327688A (en) * 2022-03-15 2022-04-12 Tcl通讯科技(成都)有限公司 Data processing method, frame, storage medium and terminal equipment based on micro front end
CN114816637A (en) * 2022-04-27 2022-07-29 瀚云科技有限公司 Application display method, device and system embedded into applet
CN115567576A (en) * 2022-10-14 2023-01-03 数字广东网络建设有限公司 Data transmission method and device, electronic equipment and storage medium
WO2023070834A1 (en) * 2021-10-25 2023-05-04 同程网络科技股份有限公司 Method and system for communication between applet and webpage, and related device
CN116881602A (en) * 2023-07-12 2023-10-13 中国平安人寿保险股份有限公司 Interaction method and device of application program and webpage and computer equipment

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110704054A (en) * 2019-09-06 2020-01-17 北京达佳互联信息技术有限公司 Method and device for accessing target application program through applet, electronic equipment and storage medium
CN111414525A (en) * 2020-03-25 2020-07-14 深圳市腾讯网域计算机网络有限公司 Data acquisition method and device for small program, computer equipment and storage medium

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110704054A (en) * 2019-09-06 2020-01-17 北京达佳互联信息技术有限公司 Method and device for accessing target application program through applet, electronic equipment and storage medium
CN111414525A (en) * 2020-03-25 2020-07-14 深圳市腾讯网域计算机网络有限公司 Data acquisition method and device for small program, computer equipment and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
衡与墨: "微信小程序(1)——web-view和小程序间传递参数、发送消息", pages 1 - 2, Retrieved from the Internet <URL:https://blog.csdn.net/le_17_4_6/article/details/86598772> *

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023070834A1 (en) * 2021-10-25 2023-05-04 同程网络科技股份有限公司 Method and system for communication between applet and webpage, and related device
CN114217866A (en) * 2021-11-08 2022-03-22 阿里健康科技(中国)有限公司 Applet using method and device and electronic equipment
CN114217866B (en) * 2021-11-08 2023-09-19 阿里健康科技(中国)有限公司 Application method and device of applet and electronic equipment
CN114327688A (en) * 2022-03-15 2022-04-12 Tcl通讯科技(成都)有限公司 Data processing method, frame, storage medium and terminal equipment based on micro front end
CN114327688B (en) * 2022-03-15 2022-07-08 Tcl通讯科技(成都)有限公司 Data processing method, frame, storage medium and terminal equipment based on micro front end
CN114816637A (en) * 2022-04-27 2022-07-29 瀚云科技有限公司 Application display method, device and system embedded into applet
CN114816637B (en) * 2022-04-27 2024-03-01 瀚云科技有限公司 Application display method, device and system embedded in applet
CN115567576A (en) * 2022-10-14 2023-01-03 数字广东网络建设有限公司 Data transmission method and device, electronic equipment and storage medium
CN116881602A (en) * 2023-07-12 2023-10-13 中国平安人寿保险股份有限公司 Interaction method and device of application program and webpage and computer equipment
CN116881602B (en) * 2023-07-12 2025-07-22 中国平安人寿保险股份有限公司 Interaction method and device of application program and webpage and computer equipment

Similar Documents

Publication Publication Date Title
CN112162871A (en) Method, device and storage medium for data exchange between applet and webview
US10783211B2 (en) Page processing method and device thereof
US8955739B2 (en) Barcode scanner on webpage
JP5985074B2 (en) Web resource interactivity analysis based on reload events
US10354244B2 (en) Method, apparatus and system for processing payment request for virtual commodities on open network platform
US11615443B2 (en) System and method to selectively update supplemental content rendered in placement regions of a rendered page
CN108319662A (en) Page processing method, device, electronic equipment and readable storage medium storing program for executing
CN108509207A (en) The cross-system of WEB application program is installed
CN110704784A (en) Web page screenshot method, apparatus, device and computer-readable storage medium
WO2019072024A1 (en) Credit-based installment service implementation method
CN109862076B (en) Service data interaction method, device and system
CN106656920A (en) HTTP service processing method and device
CN112632184A (en) Data processing method and device, electronic equipment and storage medium
CN109358833B (en) Audio playing method and system, computing device and storage medium
CN107948328B (en) Information pushing method and device and electronic equipment
EP3242258A1 (en) Method and apparatus for processing virtual card
JP2018500670A (en) Handling unstructured messages
CN113115238B (en) SMS verification code filling method and electronic device
CN106874485A (en) The method and picture that a kind of picture is presented are presented device
CN112230944B (en) Application installation method, device, electronic equipment and computer readable medium
CN114721740B (en) Message triggering method, device, equipment and storage medium
CN111967929A (en) Order polling method and device, electronic equipment and storage medium
CN107613486B (en) STK module naming method, communication terminal and device with storage function
CN114691236B (en) Method, device, equipment and medium for integrating native program and mini program
CN117539564A (en) Page hot updating method and device, electronic equipment and readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20210101