如何为此代码添加5秒的时间延迟?
<script type="text/javascript">
if (document.location.href.indexOf('url-wording') > -1) {
document.location.href = 'http://www.google.com/';
}
</script>
答案 0 :(得分:1)
if(document.location.href.indexOf('url-wording') > -1) {
setTimeout(function() {
document.location.href = 'http://www.google.com/';
}, 5000); // 5000ms = 5s
}