After the IFRAME is deleted from the Dom, ie9 + recycles the memory. Impact scope: Applicable to Internet Explorer 9 and later.
Scenario (rather hidden !!!) :
Define a global variable on the home page, and then let the operations in the IFRAME on the Child page update this value.
1 // Home Page 2 top. g_config ={}; // defines a global variable
1 // IFRAME page 2 3 // operation global variable 4 If ('undefined' = typeof (top. g_config ['url _ list']) {5 top. g_config ['url _ list'] = []; 6} 7 top. g_config ['url _ list']. push ('something'); 8 // after the operation is complete, disable this IFRAME
It seems that there is basically no problem, but the IFRAME page is contained in a pop-up window. After the operation, the IFRAME will be removed from the Dom. Have you noticed this line of code:
1 top.G_config[‘url_list‘] = [];
In IFRAME, an array is created for the global variable top. g_config, And the array is a complex type object in Js. Therefore, a global variable references an array created in IFRAME, Which is recycled when the IFRAME is removed from the Dom. When the global variable is operated in the pop-up window for the second time, an error is reported: the code of the released script cannot be executed.
How to avoid this problem (so easy !) :
1 // Home Page
2 top. g_config = {'url _ list': []}; // defines a global variable.
1 // IFRAME page 2 3 // operation global variable 4 top. g_config ['url _ list']. push ('something'); 5 6 // after the operation is complete, disable this IFRAME
Idea: Update global variables on the IFRAME page to avoid reference of values.
Conclusion: Do not use global variables when using JS encoding. Be cautious when you cannot avoid it. When updating global variables in IFRAME, do not reference the variables. This bug is very concealed.