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)代码>