Window.name Resolving Cross-domain data transfer problems

Source: Internet
Author: User

Original: Http://research.microsoft.com/~helenw/papers/subspace.pdf

Window.name transmission technology, originally used by Thomas Frank to solve some of the disadvantages of cookies (4 x Kb per domain limit, data can only be strings, set up and get the complexity of cookie syntax, etc.) and invented (see the original: Session V Ariables without cookies), later Kris ZYP enhanced Window.name transmission on the basis of this method and introduced Dojo (dojox.io.windowName) to solve Cross-domain data transfer problems.

The beauty of Window.name:name values still exist after different pages (or even different domain names) are loaded, and can support very long name values (2MB).

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:

(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;
};
})();



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.