ソースを参照

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

Malcolm Scruggs 5 年 前
コミット
a0daff92c0
共有1 個のファイルを変更した16 個の追加0 個の削除を含む
  1. 16
    0
      docs/Reference.md

+ 16
- 0
docs/Reference.md ファイルの表示

@@ -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`