1.0.1 • Published 1 year ago
crossbow-of-cors v1.0.1
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
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")```javascript
* __Set local Storage__ ```javascript // return type Boolean crossbow.setLocalStorage({key: "user", value: "user-1"})
Delete local Storage
```javascript
// return type Boolean crossbow.deleteLocalStorage("key")
// return type Boolean crossbow.deleteLocalStorage("key1","key2")