Browse Source

chore(docs): Create example for injectedJavaScript (#571)

Malcolm Scruggs 5 years ago
parent
commit
a0daff92c0
1 changed files with 16 additions and 0 deletions
  1. 16
    0
      docs/Reference.md

+ 16
- 0
docs/Reference.md View File

@@ -115,6 +115,22 @@ Set this to provide JavaScript that will be injected into the web page when the
115 115
 
116 116
 To learn more, read the [Communicating between JS and Native](Guide.md#communicating-between-js-and-native) guide.
117 117
 
118
+Example:
119
+
120
+Post message a JSON object of `window.location` to be handled by [`onMessage`](Reference.md#onmessage)
121
+
122
+```jsx
123
+const INJECTED_JAVASCRIPT = `(function() {
124
+    window.ReactNativeWebView.postMessage(JSON.stringify(window.location));
125
+})();`;
126
+
127
+<WebView
128
+  source={{ uri: 'https://facebook.github.io/react-native' }}
129
+  injectedJavaScript={INJECTED_JAVASCRIPT}
130
+  onMessage={this.onMessage}
131
+/>
132
+```
133
+
118 134
 ---
119 135
 
120 136
 ### `mediaPlaybackRequiresUserAction`