Many frameworks have a parent-child relationship, which is very troublesome to operate. Many of you often see this miserable code. Many frameworks have a parent-child relationship, which is very troublesome to operate, many people often see such sad code:
The Code is as follows:
Extends extends parent.doc ument. getElementById ("main ")
.ContentWindow.doc ument. getElementById ('input'). value =
Document. getElementById ('myiframe ')
.Content1_doc ument. getElementById ('s0'). value;
In fact, this problem can be greatly simplified. There is a fixed window in the framework application called window. top: If we cache data to this page, all the frameworks under it can be obtained, no matter how the sub-page changes. No Cookie or HTML5 local database policy is required. You only need to reference a js file on each page. The content is as follows:
The Code is as follows:
Var share = {
/**
* Cross-framework data sharing interface
* @ Param {String} refers to the data name stored
* @ Param {Any} Any data to be stored (the queried data is returned if this item is not included)
*/
Data: function (name, value ){
Var top = window. top,
Cache = top ['_ cache'] || {};
Top ['_ cache'] = CACHE;
Return value? Cache [name] = value: cache [name];
},
/**
* Data Sharing and deletion Interface
* @ Param {String} The Name Of The Deleted Data
*/
RemoveData: function (name ){
Var cache = window. top ['_ cache'];
If (cache & cache [name]) delete cache [name];
}
};
The method with a few lines can share any type of data for each frame page to read. It has nothing to do with the page name and level, even if the Framework page level is modified someday, you don't have to worry about it. It works properly.
For example, we can store shared data on page:
The Code is as follows:
Share. data ('myblog', 'HTTP: // www.jb51.net ');
Share. data ('edittitle', function (val ){
Document. title = val;
});
Then, the data of page A is retrieved from any frame page.
The Code is as follows:
Alert ('My blog address is: '+ share. data ('myblog ');
Var editTitle = share. data ('edittitle ');
EditTitle ('I have obtained the data ');
Yes, that's easy! You can also see this technology in the iframeTools extension of artDialog.