页面跳转的几种方法

PHP

<?php

//302重定向 缺少http://会造成重复重定向
$url = "http://www.cnblogs.com/mengor";   
header( "Location: $url" ); 

//301重定向
$url = "http://www.cnblogs.com/mengor";   
header( "HTTP/1.1 301 Moved Permanently" );   
header( "Location: $url" ); 

//多用于参数错误跳转前-页面
echo "<script>alert('没有文件上传');history.back(-1)</script>";exit;
 
//上级页面跳转   多用于后台frame框架(防止出现画中画)
 echo "<script>top.location.href='$url';</script>";exit;
 

top.location.href=”url”          在顶层页面打开url(跳出框架)

self.location.href=”url”         仅在本页面打开url地址   

parent.location.href=”url”      在父窗口打开Url地址   

this.location.href=”url”       用法和self的用法一致

window.open('url');        打开一个新窗口

if (top.location == self.location) 判断当前location 是否为顶层来 禁止frame引用

实际中可能这样使用  if(top !== self){             top.location.href = location.href;         }   禁止frame引用

 
 

//关闭当前窗口刷新父窗口(多用于接口回调)
echo '<script>window.opener.location.reload();window.close();</script>';

 

meta

<meta http-equiv="refresh" content="5;url=http://www.cnblogs.com/mengor"> 

js

<script> 
    window.location.href="http://www.cnblogs.com/mengor";
</script> 
//a链接父级页面跳转
<a href="{:url('haowai/other/index',['member_find_id' => $vol.member_id])}" target="_parent" ><img src="{$vol.member_avatar}" class="touxiang" /></a>

 

转载于:https://www.cnblogs.com/mengor/p/8242083.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值