UNPKG

@dead_fish/jsbridge

Version:

A lightweight and easy-to-use jsBridge for Android and IOS platforms.

86 lines (64 loc) 1.62 kB
```shell npm install @dead_fish/jsbridge ``` `Native IOS or Native Android communication bridge for webview. H5 and Native communication bridge.` `JsBridge is a lightweight bridge for communication between webview and native. IOS and Android are supported` # Usage # ES ```javascript import { jsBridge, utils } from '@dead_fish/jsbridge'; const query = utils.parseUrl() jsBridge.registerHandler({ eventName: 'eventName', handler: function (data, callback) { console.log(data); } }) jsBridge.callHandler({ eventName: 'eventName', data: {}, handler: function (response) { console.log(response) } }) ``` # CommonJS ```javascript const { jsBridge, utils } = require('@dead_fish/jsbridge'); const query = utils.parseUrl() jsBridge.registerHandler({ eventName: 'eventName', handler: function (data, callback) { console.log(data); } }) jsBridge.callHandler({ eventName: 'eventName', data: {}, handler: function (response) { console.log(response) } }) ``` # Browser ```html <script src="./node_modules/@dead_fish/jsbridge/dist/bundle.umd.js"></script> <script> const jsBridge = window.dhLib.jsBridge; const utils = window.dhLib.utils; const query = utils.parseUrl() jsBridge.registerHandler({ eventName: 'eventName', handler: function (data, callback) { console.log(data); } }) jsBridge.callHandler({ eventName: 'eventName', data: {}, handler: function (response) { console.log(response) } }) </script> ```