jsp页面等等几秒后,自动运行javascript中的函数!!!!

jeff1114 2011-03-30 10:07:58
代码是:

<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'Extractpage.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<style type="text/css">
.white_content {
display: block;
position: absolute;
top: 25%;
left: 35%;
width: 25%;
height: 8%;
padding: 1px;
border: 1px solid #51b2f6;
background-color: white;
z-index:1002;
overflow: auto;
}

</style>

</head>
<%
String type=(String)request.getAttribute("type");
%>
<script>
var type='<%=type%>';
function extract()
{
if(type=="yuqing")
{
document.myform.action="../ExtractYuqing.jsp";
document.myform.submit();
}else if(type=="taskevent")
{
document.myform.action="../SearchAllEvent?method=sourceShow";
document.myform.submit();
}
}
extract();
</script>
<body>
<form action="" id="myform" name="myform" method="post">

<div id="light" class="white_content" align="center">
<img src='img/loading.gif' width='160' height='20' />
<br>
正在处理中,请稍候...
</div>
</form>
</body>
</html>



现在需要的是,进入这个页面后,等待5秒后,自动运行 extract()函数,从而进行页面的跳转,请问怎么实现啊
在网上找的方法是 <meta http-equiv="refresh" content="5;URL=http://www.baidu.com"> 但这个方法只能跳转到固定的网址,不能运行js中的函数!!!
...全文
862 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
jeff1114 2011-04-02
  • 打赏
  • 举报
回复
谢谢各位了,问题解决了
使用 setTimeout("extract()",5000);就行了
rainsilence 2011-03-30
  • 打赏
  • 举报
回复
楼上只有setTimeout方法是对的。不能用setInterval,因为setInterval执行N次,setTimeout只执行一次
xdrs1314 2011-03-30
  • 打赏
  • 举报
回复
楼上都回答的很清楚。
原来 2011-03-30
  • 打赏
  • 举报
回复
放到定时器里面吧
luman2002 2011-03-30
  • 打赏
  • 举报
回复

<script>
var type='<%=type%>';
function extract()
{
if(type=="yuqing")
{
document.myform.action="../ExtractYuqing.jsp";
document.myform.submit();
}else if(type=="taskevent")
{
document.myform.action="../SearchAllEvent?method=sourceShow";
document.myform.submit();
}
}
var Int;
Int = setInterval("extract()", 5000);
//其中5000为时间,1秒=1000.
</script>



qingyuan18 2011-03-30
  • 打赏
  • 举报
回复
查js的settimeout函数,在<body>加onload=你的延迟加载函数,或者把你的函数放到jsp页面末尾
head_first 2011-03-30
  • 打赏
  • 举报
回复
页面装载完成后,会延迟5秒执行你要的函数
lorry1113 2011-03-30
  • 打赏
  • 举报
回复
body上添加 onload="onload"
function onload(){
setTimeout(functionName,5000);
}
页面加载完成后会自动执行onload
head_first 2011-03-30
  • 打赏
  • 举报
回复

function wait(){
setTimeout(extract(),5000);
}
var type='<%=type%>';
function extract()
{
if(type=="yuqing")
{
document.myform.action="../ExtractYuqing.jsp";
document.myform.submit();
}else if(type=="taskevent")
{
document.myform.action="../SearchAllEvent?method=sourceShow";
document.myform.submit();
}
}
// extract();




...
<body onload="wait();">
...
zqfddqr 2011-03-30
  • 打赏
  • 举报
回复
就是倒计时跳转呗先开始读秒然后跳转
http://blog.csdn.net/hn1232/archive/2009/06/02/4235060.aspx
http://www.phphtm.com/2011/0109/2226.html
yaoweijq 2011-03-30
  • 打赏
  • 举报
回复
body onload=""
里面执行一个js
这个js里面延迟5秒后执行你的逻辑
lyhmy 2011-03-30
  • 打赏
  • 举报
回复
你把那段代码放到<base href="<%=basePath%>">前试下

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧