WEB开发中的页面跳转方法总结

1、PHP header()调转

<?php
//302跳转
$url = "http://www.baidu.com/";
header("Location: $url");

//301跳转
if($_GET['t']=='301')
header( "HTTP/1.1 301 Moved Permanently" ); header("Location: $url" ); ?>

2、Javascript跳转

a.有来路的跳转

<script>
//有来路
var aa = document.createElement("a");
aa.setAttribute("href","http://www.baidu.com");
var bodys=document.getElementsByTagName("body")[0];
bodys.appendChild(aa);
aa.click();
</script>

b.无来路的跳转

<script>
window.location.href="http://www.baidu.com";
</script>

注意,上面这段代码直接跳转后,在目标页面地址中是获取不到来路(referer,也叫来源)的,在实际项目中,

遇到有客户要求跳转要带来路(即目标网页可以获取到页面从哪里跳转来的),这时,我们可以用javascript模拟一次点击,然后跳转就满足了客户的需求。

3、Meta跳转

<meta http-equiv="refresh" content="5;url=http://www.baidu.com">
原文地址:https://www.cnblogs.com/wuheng1991/p/5127890.html