一个动态的倒计时404页面自动跳转JS代码,以本博客WordPress为例把下面的代码添加到主题404.php文件内。
代码如下:
- <script?language='javascript'?type='text/javascript'>
- ?????????var?secs?=?6;?//倒计时的秒数
- ?????????var?URL;
- ?????????function?Load(url)?{
- ?????????????URL?=?url;
- ?????????????for?(var?i?=?secs;?i?>=?0;?i--)?{
- ?????????????????window.setTimeout('doUpdate('?+?i?+?')',?(secs?-?i)?*?1000);
- ?????????????}
- ?????????}
- ?????????function?doUpdate(num)?{
- ?????????????document.getElementById('ShowDiv').innerHTML?=?'<h2>还有<span?style="color:red">'?+?num?+?'</span>秒后自动反回首页<h2>';
- ?????????????if?(num?==?0)?{?window.location?=?URL;?}
- ?????????}
- ????</script>
- </head>
- <body>
- ????<script?language="javascript"?type="text/javascript">Load("https://wosn.net");?//网址修改成你要跳转的默认首页</script>
- ????<div?id="ShowDiv"></div>
- </body>
评论