您的位置:首页 > 编程语言 > Go语言

window.location.reload();history.back(-1);history.go(1);多种页面刷新跳转详解

2014-07-04 08:45 661 查看
window.location.reload();history.back(-1);history.go(1);多种页面刷新跳转详解

go(-1): 返回上一页, 原页面表单中的内容会丢失; 

back(-1): 返回上一页, 原页表表单中的内容会保留.

<input type=button value=刷新 onclick="window.location.reload()">

<input type=button value=前进 onclick="window.history.go(1)"> 

<input type=button value=后退 onclick="window.history.go(-1)">

<input type=button value=前进 onclick="window.history.forward()"> 

<input type=button value=后退 onclick="window.history.back()">

后退+刷新<input type=button value=后退 onclick="window.history.go(-1);window.location.reload()">

history.back()是会上一页

i=1

history.go(i)去指定的某页

如果是history.go(0)那就是刷新这两个属于JS代码,相当于IE的前进、后退功能。

具体的用处就要看什么时候需要这个就用上。比如用户注册时的验证是后台验证,不符合要求的时候就可以用这个,可以最大限度保证用户少重复输入数据。

例如:载入页面:

function onLoadPage(){

if(event.srcElement.tagName=="SPAN"){

oFrame=top.window.middle.frames[2];

oTxt=event.srcElement.innerText;

switch(oTxt){ 

case "前 进":

oFrame.history.go(1);

case "后 退":

oFrame.history.back();

case "刷 新":

oFrame.location.reload();

}

}

}

1、用HTTP头信息:

<?php

if(isset($url))

{

header("Location: $url"); //只是跳转,所以一定要用die();或者exit;终止下一步操作;

exit;

}

?>

2、用HTML标记:

<head>

<META HTTP-EQUIV="PEFRESH" CONTENT="5; URL=<?php echo $url;?>">

</head>

或者

echo "< meta http-equiv=\\"Refresh\\" content=\\"秒数; url=跳转的文件或地址\\" > ";

其中:XX是秒数,0为立即跳转.refresh 是刷新的意思.Url 是要跳转到的页面.

3、

<script>url="submit.php";window.location.href=url;</script> 

<script>url="submit.php";window.open(\'url,\'\',\'_self\');</script>  可以限制原窗口还是父窗口,子窗口或者新窗口

4、在CI框架中可以用redirect();跳转,之后不执行下一步操作; (但是这不是php函数)

谢谢关注websites博客!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息