From db529e265f318bf52f872400f0c6d5970192e055 Mon Sep 17 00:00:00 2001 From: Leonardo Russo Date: Tue, 25 Aug 2020 10:02:13 -0300 Subject: [PATCH] Updated Guide.md for using injectedJavaScript (#1578) https://github.com/react-native-community/react-native-webview/issues/1554 --- docs/Guide.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/Guide.md b/docs/Guide.md index c578f28..134defe 100644 --- a/docs/Guide.md +++ b/docs/Guide.md @@ -305,6 +305,7 @@ export default class App extends Component { uri: 'https://github.com/react-native-community/react-native-webview', }} + onMessage={(event) => {}} injectedJavaScript={runFirst} /> @@ -313,7 +314,7 @@ export default class App extends Component { } ``` -This runs the JavaScript in the `runFirst` string once the page is loaded. In this case, you can see that both the body style was changed to red and the alert showed up after 2 seconds. +This runs the JavaScript in the `runFirst` string once the page is loaded. In this case, you can see that both the body style was changed to red and the alert showed up after 2 seconds. An `onMessage` event is required as well to inject the JavaScript code into the WebView. By setting `injectedJavaScriptForMainFrameOnly: false`, the JavaScript injection will occur on all frames (not just the main frame) if supported for the given platform. For example, if a page contains an iframe, the javascript will be injected into that iframe as well with this set to `false`. (Note this is not supported on Android.) There is also `injectedJavaScriptBeforeContentLoadedForMainFrameOnly` for injecting prior to content loading. Read more about this in the [Reference](./Reference.md#injectedjavascriptformainframeonly).