react-native: [WebView] WebView on android can`t execute javascript
<WebView
style={[styles.webview, {
height: this.state.height || 400
}]}
javaScriptEnabled={true}
bounces={false}
onNavigationStateChange={this._onNavigationStateChange}
html={this._getHTML(content)}
/>
javascript inside WebView page do not execute. On iOS it works fine.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 29 (12 by maintainers)
Set true both
javaScriptEnabled
anddomStorageEnabled
The issue seems to depend on the android SDK version. using 23 fails and it works using version 24 and 25 . this might require more testing on real device like samsung to see if it works on 23 on some real devices.
Worked for me by adding baseUrl like this:
<WebView javaScriptEnabled={true} source={{html: myHtml, baseUrl: “/”}} />
on android I got it finally to work after I’ve put semicolon “;” at the end of every command, for example;
this works:
and this breaks the whole javascript, check line 2 in “jsCode” in the variable:
menuButton.parentNode.removeChild(menuButton) <- is missing semicolon
I can confirm that WebView Javascript code is not executed on android 4.4.2 device (API 19) and maybe some higher versions of android. Neither inside <script></script> blocks in html, neither inside injectedJavaScript prop. Tried everything described here. I use RN 0.50.0. Have someone faced with this issue and solved it somehow?
I’ve figured out Android WebView bug. Even in Android API >= 23 and react-native 0.52. => If your JavaScript code contain any comment => javascript will not run
I have to remove every comments in order for JavaScript to run.
In ios, comments is fine. Android is so weird.
I tried to use react-native-webview-android the Javscript inside page didn
t execute. But javascript through
injectedJavaScript` worked@satya164 I have tried that. Didn
t work. Tried to use
injectedJavaScriptdidn
t work either