I have an iPad app that contains a webview. The webview's page has a button on it that, when clicked, needs to somehow tell the native app to close the webview. Is there any way to do this? i.e. a way for the javascript in the webview to pass messages to the native app, and vice-versa?
Thanks!
2 — Android: 2.1 To receive data from webview ,we can create an interface, which will enable webview to connect the native layer and pass data. From native layer, create a class and replicate the following. While configuring web view, we need to set JavaScript interface as above JSBridge class.
Import the React Native WebView package in App. js . We will create a normal HTML page in WebView and use “script” tags to let the HTML page communicate with the React Native app. In the “script” tag, we are going to call a sendDataToReactNativeApp() function in which we will use a window property called window.
Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.
You can consider using -webView:shouldStartLoadWithRequest:navigationType:
. Create a dummy link which you can identify and close the web view. As for the other way round, @Paska's answer sounds appropriate.
Maybe have an NSNotification
fire when an NSString
instance field is changed. Use the post here to help understand how to communicate between JavaScript and Objective-C.
Then, it is just a matter of notification and string logic:
Steps for JavaScript to Objective-C:
Not sure what you want to pass back to the Web view from Objective-C, but the above post should help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With