It's a hassle to pass data to the parent window or to the child window, and if we can write a permanent interface that's convenient, here's a brief introduction to how to implement this feature. The principle is to window.top the data cache as early as possible, so that the data will always remain unchanged regardless of how the parent window of the child window changes.
The code is as follows:
var share={
data:function (name,value) {
var top=window.top,
cache=top[' _cache ']| | {};
top[' _cache ']=cache;
return value?cache[name]=value:cache[name];
},
removedata:function (name) {
var cache=window.top[' _ CACHE '];
if (Cache&&cache[name])
{
delete cache[name];}}
;
The above code to achieve our requirements, the code is relatively simple, we can analyze their own, if you have any questions can post message.
Do you know how to pass the value of the IFRAME in JS? Below to give you a brief introduction.
1. Get the elements of the parent page in the IFRAME child page:
A>window.parent.document This is the object that gets the parent page document;
B> If you want to get the method in the parent page JS: window.parent.xxxx (); xxxx () is the method;
2. Get the elements from the IFRAME child page in the parent page:
A>
var child = document.getelementbyidx_x ("MainFrame"). Contentwindow;//mainframe this ID is the ID of the parent page iframe
child.document;//gets the document object in the child page;