The client calls the js method in the web (C call B) for cross-origin issues, webjs

Source: Internet
Author: User

The client calls the js method in the web (C call B) for cross-origin issues, webjs

These days, I encountered a difficult problem (c debugging B) and found out the problem through troubleshooting.

I. The problem is described as follows:

1.client terminal invoke a js method in father.html. The special feature is that this father.html contains an iframe embedded with a son. jsp. In essence, the client needs to call son. jsp.

In the getUserid ("userid") method to pass the client's userid to son. jsp. The phenomenon is that the client concatenates and modifies the js method and also transmits the userid. After stringbyevaluatingjavascriptfromstring is called to execute the js method, son. the method in jsp does not respond, that is, the client does not call this js. Description: The domain names of father.html and son. jsp are different.

2. The js method called by the C-end is not active, but the B-end sends a signal to the C-end that the C-end can execute this method, I will give you the method name. After you get it, splice it and input the parameter for execution.

Ii. troubleshooting process:

1. In the webView of the Client: shouldload.pdf, the link of father.html is obtained first, and son is obtained after execution. jsp link, and finally get son. the signal sent by jsp to the client, that is, the js method name. After receiving the signal, the passed-in parameter executes stringbyevaluatingjavascriptfromstring. At this time, son. this method on the jsp end should have a response, but it is not actually executed

2. In father.html, the same type of bcall command is also sent, and the same js method is defined in father.html. Then, the following code is re-run: The webView in the client: the js method in the pipeline is executed, and the js method in the pipeline is executed again, while. the js method in jsp is still not executed

3. When the same js method is defined in father.html, the following code is re-run: The webView of the client: the js method in idea is executed, while the js method in son. jsp is still not executed.

4. Conclusion: The js method is not found in callback, so it cannot be executed, but cannot be found in son. jsp because of cross-origin. Therefore, this js method fails to be executed. If this js method is found in father.html, run

3. solution:

1.define in father.html the js method that is the same as in son.jspinstruction. In this example, the js method in father.html will be executed, get the userid passed by the client, and then call son. in jsp, the userid is passed in and executed, so that son. jsp gets the userid. In general, it is a curve to save the country and let son. the jsp js method is indirectly executed.

2.js in the specific father.html calls the js method in son. jsp: (1) define the same document. domain = 'domain' in the <script/> block of the two, and then call

The cross-origin call of js is implemented.

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.