阅读(2176)
赞(0)
js控制页面跳转的方法
2016-08-10 14:24:59 更新
方法一
<script language="javascript" type="text/javascript">
window.location.href="login.jsp?backurl="+window.location.href;
</script>
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>
<script language="javascript">
window.navigate("top.jsp");
</script>
<script language="JavaScript">
self.location='top.htm';
</script>
<script language="javascript">
alert("非法访问!");
top.location='xx.jsp';
</script>
<script language="javascript">
var secs = 3; //倒计时的秒数
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 = '将在'+num+'秒后自动跳转到主页' ;
if(num == 0) { window.location = URL; }
}
</script>
<p style="text-indent: 2em; margin-top: 30px;">
系统将在 <span id="time">5</span> 秒钟后自动跳转至新网址,如果未能跳转,<a href="http://www.jb51.net" title="点击访问">请点击</a>。</p>
<script type="text/javascript">
delayURL();
function delayURL() {
var delay = document.getElementById("time").innerHTML;
var t = setTimeout("delayURL()", 1000);
if (delay > 0) {
delay--;
document.getElementById("time").innerHTML = delay;
} else {
clearTimeout(t);
window.location.href = "http://www.jb51.net";
}
}
</script>
代码如下:
<script language="javascript" type="text/javascript">
window.location.href="login.jsp?backurl="+window.location.href;
</script>
代码如下:
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>
方法三
代码如下:
<script language="javascript">
window.navigate("top.jsp");
</script>
方法四
代码如下:
<script language="JavaScript">
self.location='top.htm';
</script>
代码如下:
<script language="javascript">
alert("非法访问!");
top.location='xx.jsp';
</script>
隔多少秒后自动跳转到其它页(js脚本)
在<head></head>之间加入js
代码如下:
<script language="javascript">
var secs = 3; //倒计时的秒数
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 = '将在'+num+'秒后自动跳转到主页' ;
if(num == 0) { window.location = URL; }
}
</script>
然后在<body>里面加上<body onload="Load('index.asp')"> index.asp为自己要跳转的页面。
在<body></body>之间加上<div id="ShowDiv"></div>
还有一种方法
代码如下:
<p style="text-indent: 2em; margin-top: 30px;">
系统将在 <span id="time">5</span> 秒钟后自动跳转至新网址,如果未能跳转,<a href="http://www.jb51.net" title="点击访问">请点击</a>。</p>
<script type="text/javascript">
delayURL();
function delayURL() {
var delay = document.getElementById("time").innerHTML;
var t = setTimeout("delayURL()", 1000);
if (delay > 0) {
delay--;
document.getElementById("time").innerHTML = delay;
} else {
clearTimeout(t);
window.location.href = "http://www.jb51.net";
}
}
</script>