Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 加载后如何延迟Webview页面的警报?_Javascript_React Native_React Native Webview - Fatal编程技术网

Javascript 加载后如何延迟Webview页面的警报?

Javascript 加载后如何延迟Webview页面的警报?,javascript,react-native,react-native-webview,Javascript,React Native,React Native Webview,我有以下资料: 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={styl

我有以下资料:

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}
  />;
}
从“React”导入React;
从“react native”导入{View,ActivityIndicator};
从“react native WebView”导入{WebView};
导出默认函数链接(){
函数加载IndicatorView(){
返回(
)
}
const runFirst='window.alert(“您将在网页加载之前看到它”);true;
const runaftertencess='window.alert(“您已在此页面上停留10秒”);true;';
返回{}
injectedJavaScript={runFirst}
/>;
}

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

您可以使用
setTimeout
延迟执行

window.alert(“您将在网页加载之前看到此消息”);
setTimeout(`window.alert(“您已经在这个页面上停留了10秒”)`,10000)