I was finding out a way to know if webview can scroll or not, but I found nothing special. I am using react-native-webview. Is their any way to find out?
react-native-webview
supports
postMessage
method, which lets you to send a message to your app from webview. If you want to track user scrolling, you can basically set up eventListener and inject that javascript inside your webview and then send scrollOffset with postMessage to your app (where you can handle that event). Or you can just pass postMessage wit payload window.innerHeight when the document in webview loads. In order to understand how postMessage callback works you can check my example app, which was actually created for another issue (see github description), but will suite this case as well.
https://github.com/GFean/webview-example-app
Related
I want to put credit card number in a field and on clicking a button to retrieve its token. I don't find much information but the thing that I found is:
https://developer.moneris.com/Documentation/NA/E-Commerce%20Solutions/Hosted%20Solutions/Hosted%20Tokenization
I tried with it but still can't make it work. If I put this whole code in webview html part it will call the function on the first screen render. If I try to get the functions out of the webview and use them I can't take the specific iframe with document.getElementById('monerisFrame').contentWindow;
Any thoughts how can I accomplish my task?
You can use Moneris Apis to communicate in React Native :
We can create XML Post Request and connect with the Moneris server with your API Token and Store Id
Follow this blog :
https://medium.com/me/stats/post/7129b5a8b4a2
I am working with another party system. When I sent request they provide me a URL. Which I load in webview. There is no way to acces that webview. I want to go automatically to another screen after done working in webview. Is there any way?
If I understood your problem correctly, you want to load the WebView and then come back to the app again, after performing some actions.
There is a way to exchange the data between your app and WebView. Please check this article.
You can also use WebView's onNavigationStateChange prop to achieve your goal, if finishing the work is signalised by the URL change.
<WebView
onNavigationStateChange={this.yourAction}
/>
Inside my app, I'm using the WKWebView to display a website. My goal is, when user is pressing a button on this website, I want to stop an action linked to this event and replace it with my own, natively made (custom action outside the WKWebView). I've been trying to search for any solution to fetch mentioned event but unsuccessful. What more came to my mind, if there is a way to fetch a JavaScript in WKWebView, I have a possibility to add some JS script code to this site (not to delete the action I want to block). Thank you for any help.
First, do you have a permission to mess with this web site's behaviour? I assume you do, otherwise it is likely illegal.
Second, try using Safari Web Inspector with a device/simulator, and use the DOM tree and console tools to find out what is the HTML/javascript that is involved with this action on this site.
If you can't find what happens in HTML/JS yourself, feel free to post a new separate question on SO with your target URL, some HTML/JS code, and which link/action you want to replace. Tag the question with "javascript" and ask if it is possible to write some javascript to replace that particular action to some custom JS code.
Usually there are 2 types of actions: either it is something that provokes AJAX calls to a server API triggered by an event handler, or it is a plain HTML link that results in a web navigation. For both cases it is possible to write a JS script that overrides the action.
Finally, use WKUserScript to inject javascript into the page, and override the action. Use window.webkit.messageHandlers to send an event from your custom action to the app side. Use WKScriptMessageHandler to process the event in the Objective-C or Swift code.
See an example here: http://nshipster.com/wkwebkit/
I have a webapp built on Laravel that is to be displayed on a mobile app (both android and ios, which are being built using React Native) via WebView.
I managed to use evollu/react-native-fcm to generate the token.
My question is: what is the proper way to send this token to the WebView, so my webapp can relate it to a user and store it on the database?
My first idea was to pass it along to the URL being called by the WebView as a GET parameter, but the parameter always come blank on the other side, probably because the token is requested asynchronously and when the webview is called it didn't come yet.
What can I do?
Either as a url parameter or via postMessage. In both ways you have to wait until the token is available. So load the page or render the webview when the token is available. Or you pass the token via postMessage immediately after the token was received.
The postMessage method is the recommended way, because you can load the page and wait for the token at the same time.
I managed to delay the rendering until the token was ready by using an if on the render method that would not return the webview if a state "loading" is true; then in the function that gets the token I used setState to change the value of loading to false.
What I am looking for here is a way to possibly click a button inside a web browser control and have it call a sub from inside the program or have the program react to something on the page.
I am trying to make a HTML5 GUI for my application. I don't really want use any 3rd party API's to handle commands from a HTML5 interface but if I can find another alternative that would be good. But if there is no other way I would be content with using a 3rd party API.
The way I have done this in the past is to specify a special protocol for my app.
yourapp:somefunction/someparameter
Handle the Navigating event, and in your code for when that event is fired, check to see if the URL has your protocol on the front of it. If it is, set e.Cancel = true to cancel navigation, and add code to handle the URL parameters yoruself.