允许我指定目标网址的Webview组件,例如facebook.com
render() { return ( <WebView source={{uri: https://www.facebook.com}} style={{marginTop: 20}} /> ); }
这是我用于以前项目的Webview.
原文链接:/react/301309.html<WebView ref="webview" source={{uri:this.state.url}} onNavigationStateChange={this._onNavigationStateChange.bind(this)} javaScriptEnabled = {true} domStorageEnabled = {true} injectedJavaScript = {this.state.cookie} startInLoadingState={false} />
对你来说必不可少的是这一行:
onNavigationStateChange={this._onNavigationStateChange.bind(this)}
你可以这样读取URL:
_onNavigationStateChange(webViewState){ console.log(webViewState.url) }
如果我没记错的话,加载网址时会发生3次火灾.
webviewState对象原型:
{ canGoBack: bool,canGoForward: bool,loading: bool,target: number,title: string,url: string,}
让我知道它是否有帮助.