Giter VIP home page Giter VIP logo

corss-storage's Introduction

localStorage跨域存储解决方案

在日常需求中: 有两个不同的域名(http://localhost:8080http://localhost:8082)想共用本地存储中的同一个 token 作为统一登录凭证:

什么是跨域?

protocol(协议)、host(域名)、port(端口)有一个地方不同都会产生跨域现象,也被称为客户端同源策略 本地存储受同源策略限制 客户端(浏览器)出于安全性考虑,无论是 localStorage 还是 sessionStorage 都会受到同源策略限制。

那么如何实现跨域存储呢?

	otherWindow.postMessage('message', targetOrigin, [transfer])

使用步骤:

  1. 使用tomcat三个服务,分别为:8080(client1.html), 8081(cross-middle.html), 8082(client2.html);
  2. client1 和 client2 的数据共享使用;

备注

日常可以把 corss-middle.html/js 单独放在一个端口,专门做跨域存储中间件使用;

corss-storage's People

Contributors

menghaor avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ruoruochen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.