React Native Webview“onNavigationStateChange”仅在 iOS 设备上返回空 document.title

Eri*_*ann 1 webview android-webview reactjs react-native react-native-webview

我正在尝试使用 Paypal 创建付款结账流程,并使用 WebView 处理 ExpressJS 后端的请求。React Native应用程序读取后端渲染的html的document.title来确定事务的成功或失败。在 Android 上它工作得很好,但是在 iOS 上 document.title 总是返回为“”。

反应本机部分:

const INJECTED_JAVASCRIPT =
    `document.getElementById('total').value="${total}"; 
    document.getElementById('address').value="${address}"; 
    document.getElementById('firstName').value="${userProfile.firstName}";
    document.getElementById('lastName').value="${userProfile.lastName}";
    document.getElementById('email').value="${accessStore.auth.userEmail}";
    document.getElementById('addressDetails').value="${moreDetails}";
    setTimeout(function() {document.f1.submit()}, 1000);`
    
    
<WebView
     source={{uri: process.env.BACKEND_NODE_URL_PAYMENT}}
     onNavigationStateChange={(data) => {
         handleResponse(data), console.log(data)
     }}
     onMessage={(event) => {}}
     injectedJavaScript={INJECTED_JAVASCRIPT}
/>
Run Code Online (Sandbox Code Playgroud)

特快专区

app.get('/success', (req, res) => {

    var PayerID = req.query.PayerID;

    var execute_payment_json = {
         "payer_id": PayerID,
    };

    var paymentId = req.query.paymentId;

    paypal.payment.execute(paymentId, execute_payment_json, function (error, payment)
    {
         if (error) {
              console.log(error.response);
              throw error;
         } else {
             res.render('success');
         }
    });
});
Run Code Online (Sandbox Code Playgroud)

在 Express JS 中呈现的 HTML

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>success</title>
</head>
<body>
<h1>Zahlung erfolgreich!</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

小智 5

我使用onLoadProgressweb 视图的属性来获取 URL e.nativeEvent

 onLoadProgress = {e => {
      let {url} = e?.nativeEvent;
}
Run Code Online (Sandbox Code Playgroud)