HTML5 How to implement the Monitoring of the APP Return Event

This article mainly introduces how HTML5 implements the monitoring of the APP, the introduction is very detailed, with certain reference value, interested friends must have read!

  Cargo query 

Click on the header The logo will return to the previous page,
// The following is the source code in mu.js, which can be seen that the following operations are performed inside when clicking returns. / $. hook = {} is specifically used to record 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)) {// Specifies Callback $ .each ($. hooks [type], callback; } Else {// Not specified Callback, execute $ .each ($. hooks [type], function (index, hook {return! hook.handle ();});}}; $. addAction = function (type, hook) {// Add history var hooks = $ .hook [type]; if (! hooks) {hooks = [];} hook.index = hook.index || 1000; hooks.push (hook); hooks.sort (Function (a, b) {Return A.index – B.index;}); $ .hook [type] = hooks; return $ .hook [type];}

When we encapsulate H5 into app, we use the 5+ interface of WebView, which is a window.
 And just started to distinguish between these two concepts, so sometimes new windows open the web, or sometimes   to jump through the URL, such as: location.href. 
This will result in a case where the BACK button listens to the phone, and the scene is roughly the following:

1, open the software to enter the home page (main.html => Hbuilder [WebView]) [The former represents the local access path of the URL, the latter is the ID of the window WebView].

2, jump to the login interface via Location.href, not to open by creating WebView.

3, after logging in, enter the function page, then press the return, return to the login page. It is expected to hope that after I log in, if you click on the back button of your phone, you directly exit. To this end, I can understand the MUI’s rollback function, we can copy thisMethod to achieve

In the page that needs to be listened:

MUI.BACK = function () {// Write you need to do it after listening to the return button

However, if it is still in accordance with the previous web page jump and creates the form of two modes, it is unexpected results, that is, mui.back can only be listened at the entrance file, in other The listening of the page or form will not be triggered, all of which are listened by the inlet file, which is captured, and only performs the listening business logic of the entry file, which will result in, when the return event is not fixed, We can’t avoid returning to the previous page: such as retreat to the login page, and the custom return event, found that all events are listened by the entrance file. This means that other pages write mui.back = function ()} is meaningless.

With all jump pages as a form, there will be no more problems. Each window can monitor MUI.BACK custom Function.

The above is how HTML5 implements all the contents of the APP to return to the event, thank you for reading! The content that wants to share is helpful to everyone, more related knowledge, welcome to pay attention to Tumi Yun Industry News Channel!
                     
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment