Bifrost-CORS
A cross-domain communication solution to share data and many more functionalities with simple as just calling a method.
Get Started
##### NPM Install
npm install bifrost-cors
CDN Link (6.39KB)
https://cdn.jsdelivr.net/gh/spurushottam13/bifrost-cors/index.min.js
GZIP version of File (1.7KB)
https://cdn.jsdelivr.net/gh/spurushottam13/bifrost-cors/index.min.gz
Functionalities can be performed on CROS Domain
- ###### Get, Set Cookie
- ###### Get, Set & Delete Local Stroage
- ###### Bi-directional message thread
- ###### Run JS expression from one domain to other
- ###### DOM Manipulation from one domain to other domain ( Iframe )
All above methods are wrapped in a promise.
Initialize Bifrost-CORS You have to Initialize Bifrost-CORS in both domain
var bifrostCors = address iframeBooleaniframeId
Parameter | Required | Value |
---|---|---|
address | YES | Exact Address of the other domain |
iframeBoolean | No | true :- If you already rendering the other domain in iframe false If you are not rendering the other domain in iframe Default false |
iframeId | No | if iframeBoolean is set to true then you need to pass the ID for your Iframe in which you loading the other domain |
Implementation of methods and how to handle promise
var bifrostCors = "http://example.com/"false //Calling Methods without promisevar result = bifrostCors //Hanlde Promise //1. Using .then()bifrostCors //2. Using async function{ let result = await bifrostCors}
Functionalities
-
Cookies
- Get Cookies
// return type Object, return all cookiesbifrostCors// return type stringbifrostCors- Set Cookies
bifrostCors-
Parameter
- name String, name for cookie
- value String, value for cookie
- days int, expiration days for cookie
-
return type Boolean
-
LocalStorage
- Get local Storage
// return type stirngbifrostCors// return type arraybifrostCors- Set local Storage
// return type BooleanbifrostCors- Delete local Storage
// return type BooleanbifrostCors// return type BooleanbifrostCors -
Bi-directional message thread
- Request Message Thread
// return type Boolean, parameter type funtionbifrostCorsListner is your custom function which will be invoked every time new message recivied, and it should expect a new message as a parameter
Here's exapmle
{cosnole}bifrostCors- Send Message
// return type Boolean, parameter type string|int|array|objectbifrostCors -
Run JS expression
// return type Boolean, parameter type stringbifrostCors -
DOM Manipulation
- DOM Manipulation by ID
// return type Boolean, parameter type stringbifrostCors- DOM Manipulation by class name
// return type Boolean, parameter type string,int,ObjetbifrostCors-
Parameter
- class String your element class name
- index int index no of that element in class array
- style Object Style object
-
Example:a if you can access element by
document.getElementsByClassName("myElementClass)[4]
so parameter will be- class "myElementClass"
- index 4
- style {background:"red"}