Created
May 16, 2017 10:15
-
-
Save niksumeiko/628e965ebe5d38e303892deffaa40172 to your computer and use it in GitHub Desktop.
Sending data from webView to native Android/iOS layer in hybrid mobile app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendToNative(data: string) { | |
if (/android/i.test(window.navigator.userAgent)) { | |
if (window.quicketNative) { | |
return window.quicketNative.send(data); | |
} | |
} | |
let frame = document.createElement('iframe'); | |
frame.width = '100'; | |
frame.height = '1'; | |
frame.src = `quicketNative:send:${encodeURIComponent(data)}`; | |
document.body.appendChild(frame); | |
document.body.removeChild(frame); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment