crossbow-of-cors
v1.0.1
Published
A cross-domain utility lib, for sharing localStorage (LiSa Team)
Downloads
3
Readme
Crossbow of CORS
A simple cross-domain communication solution to share data .
Get Started
NPM Install
npm i crossbow-of-cors
Functionalities can be performed on CROSS Domain
[Get, Set & Delete Local Storage]
How to implement methods and promise handling
| Parameter | Required | Value | | :------------- |:---------------------|:-----| | host | Yes | Exact Address of the other domain| | useIframe| No | true : If you want to create & render other iframe domain false: If you are not rendering the other domain in iframe (use message listener only) Default false | | iframeID | No | If you want to render iframe that you created in outside lib, set useIframe=false, and pass your iframe element ID to iframeID |
Setup
// publisher or messenger (example.com)
var crossbow = new CrossbowPublisher("http://example2.com", true)
// receiver or listener (example2.com)
new CrossbowListener("http://example.com").init()
Example
var crossbow = new CrossbowPublisher("http://localhost:3001", true)
//Calling Methods without promise
var result = crossbow.getLocalStorage(key)
//Promise
//1. Using .then()
crossbow.getLocalStorage(key).then((data) => {
console.log(data)
})
//2. Using async function
async function getData(){
let result = await crossbow.getLocalStorage(key)
}
Functionalities
LocalStorage
- Get local Storage
// return type string crossbow.getLocalStorage("key") // return type array crossbow.getLocalStorage(["key1","key2"])
- Set local Storage
// return type Boolean crossbow.setLocalStorage({key: "user", value: "user-1"})
- Delete local Storage
// return type Boolean crossbow.deleteLocalStorage("key") // return type Boolean crossbow.deleteLocalStorage(["key1","key2"])