Window.name transmission technology, was originally Thomas FrankIt was invented to address some of the disadvantages of cookies (4 Kb per domain limit, data can only be strings, set and get the complexity of cookie syntax, and so on) (see Text in detail: "Session Variables without cookies"), and later Kris ZypOn the basis of this method, the Window.name transmission is strengthened and introduced into the Dojo( Dojox.io.windowNameTo resolve cross-domain data transfer issues.
The basic principle and steps of Window.name transmission technology are:
Name is a property of a global/window object in the browser environment, and the property value of name remains unchanged when a new page is loaded in the frame. By loading a resource in the IFRAME, the target page sets the Name property of the frame. This Name property value can be fetched to access the information sent by the Web service. However, the Name property is accessible only to the frame of the same domain name. This means that in order to access the Name property, when the Remote Web service page is loaded, the frame must be navigated back to the original domain. The homology policy still prevents other frame from accessing the Name property. Once the Name property is obtained, destroy the frame.
At the top level, the Name property is unsafe and any information that is set in the Name property is available for all subsequent pages. However, the Windowname module always loads resources in an IFRAME, and once you get the data, or when you browse a new page at the top, the IFRAME will be destroyed, so the other pages will never be accessible to the Window.name property.
Basic implementation code, based on YUI, from the Kerjun written sample:
Copy Code code as follows:
(function () {
var yud = YAHOO.util.Dom, YUE = YAHOO.util.Event;
Datarequest = {
_doc:document,
CFG: {
Proxyurl: ' proxy.html '
}
};
Datarequest.send = function (sURL, fncallback) {
if (!surl | | typeof surl!== ' string ') {
Return
}
sURL + = (surl.indexof ('? ') > 0? ' & ': '? ' + ' windowname=true ';
var frame = this._doc.createelement (' iframe '), state = 0, self = this;
This._doc.body.appendchild (frame);
Frame.style.display = ' None ';
var clear = function () {
try{
Frame.contentWindow.document.write (");
Frame.contentWindow.close ();
Self._doc.body.removechild (frame);
}catch (e) {}
};
var getData = function () {
try{
var da = frame.contentWindow.name;
}catch (e) {}
Clear ();
if (fncallback && typeof fncallback = = ' function ') {
Fncallback (DA);
}
};
Yue.on (frame, ' load ', function () {
if (state = = 1) {
GetData ();
else if (state = = 0) {
state = 1;
Frame.contentWindow.location = SELF.CFG.PROXYURL;
}
});
FRAME.SRC = sURL;
};
})();
Current 1/2 page
12 Next read the full text