When alert () is added to js Code, the execution is successful. If this parameter is not added, it will be incorrect!

Source: Internet
Author: User

Problem:

I am working on a project. There are two windows, one is the main window and the other is the window. open subwindow. now, after processing the corresponding event in the main window, call the corresponding function of the subwindow to pass some information and modify the content of the subwindow. Because it is done in the JavaScript code of the main window, it is found that after the subwindow function is called, the content of the subwindow has not changed, after alert () is added before the code of the subwindow function called by the Javascript in the main window, the content of the subwindow is changed correctly.

Possible situations:

In this case, a code after alert () can be used only when the page elements enter a certain State. After alert () is added, it is equivalent to a page element that has enough time to enter a certain State. If you are sure that your code is correct, you can put the code after alert () into a setTimeout function, that is to say, it should be okay to stop and run the following code.

Solution:

As mentioned above, my situation should be that the sub-window page elements have not been loaded, and the method to change the content of the sub-window page is called, resulting in no effect.

Put the corresponding code in setTimeout (), and the execution is delayed for one second. Everything is normal.

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.