alinz / react-native-webview-bridge

React Native Webview with Javascript Bridge
MIT License
1.37k stars 491 forks source link

injectedJavaScript not work at all #245

Open jeffzing opened 7 years ago

jeffzing commented 7 years ago

I want to autoplay webview "video",but the video still can not autoplay, anything wrong with my code?

let jscodeTest = 'document.addEventListener("DOMContentLoaded", init, false);' + 'function init() {'+ 'document._video = document.getElementsByTagName("video")[0];' + 'document._video.play();}';

<WebView source={{uri:'https://v.qq.com/iframe/player.html?vid=v0561w7vjli&tiny=0&auto=0',method: 'GET'}} javaScriptEnabled={true} ref="myWebView" injectedJavaScript={jscodeTest} domStorageEnabled={true} allowsInlineMediaPlayback={true} mediaPlaybackRequiresUserAction={false} scalesPageToFit={false} style={styles.backgroundVideo}/>

jeffzing commented 7 years ago

let jscodeTest = 'document.addEventListener("DOMContentLoaded", init, false);' + 'function init() {'+ 'document._video = document.getElementsByTagName("video")[0];' + 'document._video.play();}'

<WebView source={{uri:'https://v.qq.com/iframe/player.html?vid=v0561w7vjli&tiny=0&auto=0',method: 'GET'}} javaScriptEnabled={true} ref="myWebView" injectedJavaScript={jscodeTest} domStorageEnabled={true} allowsInlineMediaPlayback={true} mediaPlaybackRequiresUserAction={false} scalesPageToFit={false} style={styles.backgroundVideo}/>

zhangwen9229 commented 2 years ago

document.addEventListener("DOMContentLoaded" not working at here. remove document.addEventListener("DOMContentLoaded", then it will be ok. you can try it.

jeffzing commented 2 years ago

great ,thanks

发自我的iPhone

在 2022年1月13日,下午2:13,zhangwenshun @.***> 写道:

 document.addEventListener("DOMContentLoaded" not working at here. remove document.addEventListener("DOMContentLoaded", then it will be ok. you can try it.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.