Example of how to handle events returned by listening in Html5 APP, html5app

Source: Internet
Author: User

Example of how to handle events returned by listening in Html5 APP, html5app

When using the MUI framework, we often use a class with a. mui-action-back header.

<Header class = "mui-bar-nav"> <a class = "mui-action-back mui-icon-left-nav mui-pull-left "> </a> 

Click the return ID of the header to return to the previous page,

// Below is mui. the source code in js shows that the following operations are performed internally when you click return. // $. hook = {} is used to record the browsing history. $. Back = function () {if (typeof $. options. beforeback = 'function') {if ($. options. beforeback () === false) {return ;}}$. doAction ('backs') ;};$. doAction = function (type, callback) {// returns the previous record if ($. isFunction (callback) {// specify callback $. each ($. hooks [type], callback);} else {// No callback is specified and $. each ($. hooks [type], function (index, hook) {return! Hook. handle () ;};}};$. addAction = function (type, hook) {// Add historical records var hooks = $. hooks [type]; if (! Hooks) {hooks = [];} hook. index = hook. indexes | 1000; hooks. push (hook); hooks. sort (function (a, B) {return. index-B. index;}); $. hooks [type] = hooks; return $. hooks [type];};

When we encapsulate H5 into an APP, the 5 + interfaces we use have the concept of webview, which is a window.

At the beginning, I did not specifically distinguish between the two concepts, so sometimes new windows open web pages, or sometimes directly

Jump through the URL, for example, location. href.

This will cause a situation when listening for the back button of the mobile phone. The scenario is roughly as follows:

1. Open the software into the main page (main.html => HBuilder [webview]) [the former indicates the local access path of the URL, and the latter indicates the ID of the webview window ].

2. Jump to the logon interface through location. href instead of creating a webview.

3. log on to the function page, press return, and return to the logon page. It is expected that, after I log on, if I click the return key on the mobile phone, I will exit directly. For this reason, we have learned about the MUI rollback function. We can use this method to implement it.

On the page for listening:

Mui. back = function () {// write the operation you need to perform after listening for the Return key

However, if you use both the previous webpage jump and form creation modes, unexpected results will occur, that is, mui. back can only be listened to in the entry file. The listening on other pages or forms will not be triggered, and all the listening events of the entry file are mui. the back capture only executes the listening service logic of the entry file, which leads to the failure to return the embarrassing situation of the previous page without customizing the returned event: for example, the logon page is rolled back, and the custom return event finds that all events are listened to by the portal file. This means that writing mui. back = function () {} on other pages is meaningless.

When all the jump pages are opened as forms, the above issues will not occur. Every window can normally listen to the custom mui. back function.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.