javascript - 如何在反应原生 webview 中显示弹出选项卡?
问题描述
我有一个网页,如果用户订阅,则加载一本书,否则如果订阅过期,它将加载此页面:
我在渲染之前将页面加载到变量中以使用户体验顺利进行,然后将变量附加到 webview 的 HTML 中。负载工作正常,但是当我单击以下按钮时没有任何反应,我希望进行与网络上相同的交互。我怎样才能使用 react native webview 来实现这一点。
这是 webview 代码:
<WebView
key={this.state.value}
ref={webview => this.setState({WebViewRef:webview})}
javaScriptEnabled={true}
domStorageEnabled={true}
scalesPageToFit={false}
onLoadEnd={
this.setState({
visibleBack:false
})
}
automaticallyAdjustContentInsets={false}
source={{ html:htmlString,}} style={{height : this.state.webViewHeight, width: this.state.notSubbedHeight== 1 ? Dimensions.get('window').width-20 :Dimensions.get('window').width-40, justifyContent:'center' ,alignItems:'center',marginTop:20}}
key={this.state.key}
injectedJavaScript={jsBeforeLoad}
onMessage= {this.onMessage}
scrollEnabled={false}
/>
这就是我如何获得 htmlString
getProductsummary = async (product) => {
this.setState({ loading: true });
const username = await AsyncStorage.getItem('username');
if(username !== undefined){
fetch(Config.backendAPI+`/cleanbook_mobile.php?idbook=${product.id}&username=${username}`)
.then((response) =>{
return response.text();
}
).then((result)=>{
let resp = result;
if (resp == null || resp == "") {
resp = "<div style=\"font-family :Georgia\" >" + Languages.SummaryVide + "</div>";
}
if(resp.includes("paypal-button-container-P")){
this.setState({notSubbedHeight:1})
}
this.setState({ summary: resp, loading: false });
}).catch((error) => console.log(error));
}else{
this.setState({
notSubbed: 1,
})
}
};
var htmlString = `<div id="summaryDiv"> ${this.state.summary} </div>`;
解决方案
推荐阅读
- javascript - 有没有办法避免这种无限循环
- python - 如何读取文件的原始数据?
- javascript - 如何在反应中对嵌套对象使用扩展运算符?
- r - facet_zoom 按日期范围从 stat_summary
- rabbitmq - 是否可以将 RabbitMQ 集群节点作为跟随者添加到现有的仲裁队列?
- reactjs - 在 azure devops 和 azure app services 上配置管道并部署 React 应用程序
- jmeter - 每次发送的请求数都在变化时编写 Jmeter 脚本
- php - 在特定的 WooCommerce 结帐字段包装器 html 标记中放置一个 span 标签
- javascript - 将帐户传递给 near-js-api 函数调用
- azure - Azure Key Vault 服务是否支持 PKCS#11?