Today made an HTML activity page, would have to be completed immediately, ready to open the end of happy heart, the results ~ ...
Product suddenly put forward need to say, to speak some of the HTML interaction and app native components hook, heart 10,000 xxx ran ~
To think in a quiet mind
In the past, we are to determine whether the client open is dependent on the backend, through the application of active splicing parameters, passed to the backend, back-end to tell the front-end of the load is in the app or app, to achieve the special features of the page
Then we found that this way and limitations too much, we can not guarantee that the client must be able to each touch screen page splicing The parameters we need, and our touch screen page has many kinds, some activities need, some dynamic, some static
And there are many ways to open the app, and the new feature page continues to grow, which leads us to have to be right before each development, to ensure its correctness, lack of fault tolerance, and lack of security, and if the client has been released it will only be re-released for remediation
Then we can not tender through the way directly through the front-end to the client side of the way to achieve, the answer is certainly possible ~, the following or from the product demand.
Products require some static resources on the page of certain connections, when opened outside the app to jump is the normal touch screen page, in the app when you open the app to jump to the original interactive page, I listen to the demand so sick of it ~
In the past, we had to translate these pages into dynamic pages, and we had to contract with the client, the workload was increased, development efficiency was reduced, and page performance was affected.
This led me to seek a new solution.
First, I used a static page to pick up a client's JS method to provide hints
is not defined
What the hell, usually we see
Undefined
What is it not defined?
The literal meaning is undefined, that is, not stated. This is the variable (the object) is not at all, as follows:
Console.log (ABC); // ABC is not defined
Maybe it's smattering, we keep looking down.
are not defined and undefined differ.
Most of us know undefined, but don't know defined, undefined is undefined, as follows:
var Abc;console.log (ABC); // undefinedconsole.log (ABC.A); // so.a is undefined
This time the output is undefined. The property of the access variable will prompt is undefined that is the variable so undefined value (type);
and defined, as follows:
Console.log (ABC); // ABC is not defined
In fact, if the understanding is actually not stated. That is, the process of understanding the use of an object is to declare the value, and then determine the type of the assignment.
So summarize: is not defined precedence over undefined, that is, the first to determine whether the object is declared, if not stated directly is not defined, if already affirmed, then see if there is no assignment (type), if not so is undefined or visit The object's properties are undefined.
How to Judge undefined,undefined good judgment, as follows:
var= = undefined); // trueconsole.log (abc = = = undefined); // true; Console.log (typeof abc = = ' undefined '); // trueconsole.log (typeof abc = = = ' undefined '); trueconsole.log (!ABC); // true
And so on, there are many ways, but these are not what I need ah, how to judge is not defined, this is our focus today. , directly on the code:
Try {// fetch client method;catch (e) { = ";//Jump to touch address}
is not very simple, very efficient, we use the browser if the program error, will throw an unusual feature, to capture this operation, to perform the operation we specified;
At this point, we have a relatively perfect solution, and once again improved themselves, O (∩_∩) o haha ~
Next, let's daydream.
So can we get all the front-end and client-side interactions to be implemented in this way?
First, the client defines a JS method called by the touch screen, the function of this method is to tell the client, you are open in my client
The touch screen then calls this method, if successful, processes the page interactively into the client's mode, and if it fails, it is processed as a touchscreen version.
It is more convenient to deal with it, I do not know what a better way to do it ~ ~ ~
by Hgq
The front end determines whether the app client opens the touch screen, enabling the Jump app to interact with native components.