网页基于javaScript自动跳转方法代码举例
1 window.location.href自动跳转代码如下:
<script language="javascript" type="text/javascript">
window.location.href="/article/169it/backurl/.html"+window.location.href;
</script>
<script language="javascript" type="text/javascript">
// 以下方式直接跳转
window.location.href=/article/&/index.html
// 以下方式定时跳转
setTimeout("javascript:location.href=/article/&/index.html", 5000);
</script>
javaScript自动跳转方法的优点:灵活,可以结合更多的其他功能,缺点:受到不同浏览器的影响。
2 window.history.back自动跳转代码如下:
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>
3 window.navigate自动跳转代码如下:
<script language="javascript">
window.navigate("169it.jsp");
</script>
4 self.location自动跳转代码如下:
<script language="JavaScript">
self.location='169it.htm';
</script>
5 top.location自动跳转代码如下:
<script language="javascript">
alert("非法访问!");
top.location='169it.jsp';
</script>
6 网址从传参获得并转向代码如下:
<script language="javascript" type="text/javascript">
function request(paras){
var url = location.href;
var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");
var paraObj = {}
for (i=0; j=paraString[i]; i++){
paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);
}
var returnValue = paraObj[paras.toLowerCase()];
if(typeof(returnValue)=="undefined"){
return "";
}else{
return returnValue;
}
}
var theurl
theurl=request("url");
if (theurl!=''){
location=theurl
}
</script>