【问题标题】:How can you delay alerts for Webview pages after loading?加载后如何延迟 Webview 页面的警报?
【发布时间】:2021-05-09 05:40:28
【问题描述】:

我有以下:

import React from 'react';
import { View, ActivityIndicator } from 'react-native';
import { WebView } from 'react-native-webview';

export default function Links() { 
  function LoadingIndicatorView() {
    return (
      <View style={styles.hubLoading}>
        <ActivityIndicator color='#009b88' size='large' />
      </View>
    )
  }

  const runFirst = 'window.alert("You will see this just before the webpage loads"); true;';
  const runAfterTenSecs = 'window.alert("You have been on this page for 10 seconds"); true;';

  return <WebView 
    source={{ uri: https://google.com }}
    renderLoading={LoadingIndicatorView}
    startInLoadingState={true}
    originWhitelist={['*']}
    javaScriptEnabled={true}
    onMessage={() => {}}
    injectedJavaScript={runFirst}
  />;
}

runAfterTenSecs 当前未使用。我可以对其或runFirst 进行哪些更改,以在 Web 视图加载十秒后产生警报“您已在此页面上停留 10 秒”的预期结果?

【问题讨论】:

    标签: javascript react-native react-native-webview


    【解决方案1】:

    您可以使用setTimeout 来延迟执行。

    window.alert("You will see this just before the webpage loads");
    setTimeout(`window.alert("You have been on this page for 10 seconds")`, 10000);

    【讨论】:

      猜你喜欢
      • 2013-05-07
      • 2019-09-11
      • 1970-01-01
      • 1970-01-01
      • 2013-05-06
      • 2021-05-25
      • 1970-01-01
      • 2015-12-07
      • 1970-01-01
      相关资源
      最近更新 更多