Torture:跨域访问的功臣:window.name(Tower: the hero of cross domain access: window name)

0. 缘起

遇到一个跨域跳转,还要带上信息的问题。传统的localStorage\sessionStorage\Cookies显然无法满足我的需求了,所以另寻他法,找到一个window.name的方法挺好用的。

1. 同源

我的需求是A界面上点击表格某项跳转到对应的B界面,A界面会传值到B界面。AB非同源,顺便问一下,什么是同源?

 同源策略,即同__协议__、域名端口号,netscape浏览器规定如果有一个不满足就不允许访问另一个网页,如a.com和b.com就不是同源,那么a.com就不能得到b.com中的相关内容。
JavaScript跨域总结与解决办法 – Rain Man – 博客园 (cnblogs.com)

 同源策略,即同__协议__、域名端口号,netscape浏览器规定如果有一个不满足就不允许访问另一个网页,如a.com和b.com就不是同源,那么a.com就不能得到b.com中的相关内容。

JavaScript跨域总结与解决办法 – Rain Man – 博客园 (cnblogs.com)

2. window.name是什么

name 属性可设置或返回存放窗口的名称的一个字符串。

name 属性可设置或返回存放窗口的名称的一个字符串。

3. window.name怎么用

在不同源的情况下,之前用的三大金刚(l/s/c)就没法整(有别的方法,但是很麻烦)。我这里选择了本地跳转页面,依旧能拿到上个页面信息的方法。

// A page
window.name='str'
// B page
console.log(window.name) // 'str'

4. window家族

对象表示一个包含DOM文档的窗口,其 属性指向窗口中载入的 DOM文档 。使用 属性可以获取指定文档所在窗口。
作为全局变量,代表了脚本正在运行的窗口,暴露给 Javascript 代码。
Window – Web API 接口参考 | MDN (mozilla.org)

对象表示一个包含DOM文档的窗口,其 属性指向窗口中载入的 DOM文档 。使用 属性可以获取指定文档所在窗口。

window
document
document.defaultView

作为全局变量,代表了脚本正在运行的窗口,暴露给 Javascript 代码。

window

Window – Web API 接口参考 | MDN (mozilla.org)

4.1 Window.location

获取、设置 window 对象的 location, 或者当前的 URL.

// redirect to Url site  
window.location.href = Url;

4.2 Window.open

接口的 方法,是用指定的名称将指定的资源加载到浏览器上下文(窗口 ,内嵌框架 或者标签 )。如果没有指定名称,则一个新的窗口会被打开并且指定的资源会被加载进这个窗口的浏览器上下文中。
Window.open() – Web API 接口参考 | MDN (mozilla.org)

接口的 方法,是用指定的名称将指定的资源加载到浏览器上下文(窗口 ,内嵌框架 或者标签 )。如果没有指定名称,则一个新的窗口会被打开并且指定的资源会被加载进这个窗口的浏览器上下文中。

Window
open()
window
iframe
tab

Window.open() – Web API 接口参考 | MDN (mozilla.org)

附录

前端跨域整理 – 掘金 (juejin.cn)

Window.name – Web API 接口参考 | MDN (mozilla.org)

————————

0. Origin

When you encounter a cross domain jump, you have to bring information. The traditional localstorage \ sessionstorage \ cookies obviously can’t meet my needs, so find another way to find a window Name’s method works very well.

1. Homology

My requirement is to click an item in the form on interface a to jump to the corresponding interface B, and interface a will transfer the value to interface B. AB is not homologous. By the way, what is homology?

Homology strategy__ Agreement _< Strong > domain name < / strong >, < strong > port number < / strong >, Netscape browser stipulates that if one does not meet the requirements, it is not allowed to visit another web page. For example, a.com and b.com are not homologous, so a.com cannot get the relevant content in b.com.
JavaScript cross domain summary and Solutions – Rain Man – blog Park (cnblogs. Com)

Homology strategy__ Agreement _< Strong > domain name < / strong >, < strong > port number < / strong >, Netscape browser stipulates that if one does not meet the requirements, it is not allowed to visit another web page. For example, a.com and b.com are not homologous, so a.com cannot get the relevant content in b.com.

JavaScript cross domain summary and Solutions – Rain Man – blog Park (cnblogs. Com)

2. window.name是什么

The name property sets or returns a string containing the name of the window.

The name property sets or returns a string containing the name of the window.

3. window.name怎么用

In the case of different sources, the previous three King Kong (L / S / C) can not be integrated (there are other methods, but it is very troublesome). I chose to jump to the local page here and still get the information of the previous page.

// A page
window.name='str'
// B page
console.log(window.name) // 'str'

4. window家族

Object represents a window containing a DOM document, and its properties point to the DOM document loaded in the window. Use properties to get the window where the specified document is located.
As a global variable, it represents the window in which the script is running and is exposed to JavaScript code.
Window – Web API interface reference | MDN (Mozilla. ORG)

Object represents a window containing a DOM document, and its properties point to the DOM document loaded in the window. Use properties to get the window where the specified document is located.

window
document
document.defaultView

As a global variable, it represents the window in which the script is running and is exposed to JavaScript code.

window

Window – Web API 接口参考 | MDN (mozilla.org)

4.1 Window.location

Get and set the location of the window object or the current URL

// redirect to Url site  
window.location.href = Url;

4.2 Window.open

The < strong > < / strong > method of the interface is to load the specified resource into the browser context (window, embedded frame or label) with the specified name. If no name is specified, a new window will be opened and the specified resource will be loaded into the browser context of the window.
Window. Open () – Web API interface reference | MDN (Mozilla. ORG)

The < strong > < / strong > method of the interface is to load the specified resource into the browser context (window, embedded frame or label) with the specified name. If no name is specified, a new window will be opened and the specified resource will be loaded into the browser context of the window.

Window
open()
window
iframe
tab

Window.open() – Web API 接口参考 | MDN (mozilla.org)

appendix

Front end cross domain Consolidation – Nuggets (Juejin. CN)

Window.name – Web API 接口参考 | MDN (mozilla.org)