Window.name solves the problem of cross-domain data transmission

Window.name solves the problem of cross-domain data transmission
<br />Original text: http://research.microsoft.com/~helenw/papers/subspace.pdf
The window.name transmission technology was originally invented by Thomas Frank to solve some disadvantages of cookies (4 x 20 Kb limit for each domain name, data can only be strings, complex syntax for setting and getting cookies, etc.) (For details, see the original text: "Session variables without cookies"). Later, Kris Zyp strengthened the window.name transmission based on this method and introduced it into Dojo (dojox.io.windowName) to solve the problem of cross-domain data transmission.
The beauty of window.name: the name value persists after loading different pages (even different domains), and can support very long name values ​​​​(2MB).
The basic principles and steps of window.name transmission technology are:

name is a property of the global/window object in the browser environment, and when a new page is loaded in the frame, the property value of name remains unchanged. By loading a resource in an iframe, the target page will set the name attribute of the frame. This name attribute value can be retrieved to access the information sent by the Web service. But the name attribute is only accessible to frames with the same domain name. This means that in order to access the name attribute, you must navigate the frame back to the original domain after the remote Web service page is loaded. The same-origin policy still prevents other frames from accessing the name attribute. Once the name attribute is obtained, destroy the frame.
At the top level, the name attribute is unsafe, and any information set in the name attribute is available to all subsequent pages. However, the windowName module always loads resources in an iframe, and once the data is retrieved, or when you browse to a new page at the top level, the iframe will be destroyed, so other pages will never have access to the window.name property.
The basic implementation code is based on YUI and is derived from the example written by Kejun:

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

<<:  Analyze the problem of transferring files and other parameters in the upload component of element-ui

>>:  ie filter collection

Recommend

JavaScript canvas to load pictures

This article shares the specific code of JavaScri...

CenOS6.7 mysql 8.0.22 installation and configuration method graphic tutorial

CenOS6.7 installs MySQL8.0.22 (recommended collec...

Detailed explanation of MySQL binlog usage

binlog is a binary log file that records all DML ...

MySQL Full-text Indexing Guide

Full-text indexing requires special query syntax....

Upgrade Docker version of MySQL 5.7 to MySQL 8.0.13, data migration

Table of contents 1. Back up the old MySQL5.7 dat...

HTML Marquee character fragment scrolling

The following are its properties: direction Set th...

JavaScript to show and hide the drop-down menu

This article shares the specific code for JavaScr...

HTML table tag tutorial (32): cell horizontal alignment attribute ALIGN

In the horizontal direction, you can set the cell...

Detailed tutorial on installing Docker on CentOS 8

1. Previous versions yum remove docker docker-cli...

Detailed explanation of CSS background and border tag examples

1. CSS background tag 1. Set the background color...

How to use Javascript to generate smooth curves

Table of contents Preface Introduction to Bezier ...

Summary of MySQL5 green version installation under Windows (recommended)

1 Download MySQL Download address: http://downloa...

js canvas realizes slider verification

This article example shares the specific code of ...

CSS3 to achieve floating cloud animation

Operation effect html <head> <meta chars...

HTML tag full name and function introduction

Alphabetical DTD: Indicates in which XHTML 1.0 DT...