标签实现,当前页面a标签打开的 页面不会带有 referrer。
<meta name="referrer" content="never">
js实现。
1、借助一个新页面跳转到目标地址。
<html>
<head>
<meta charset="utf-8">
<style type="text/css" media="screen">
iframe{
display: none;
}
</style>
<body onLoad="open_without_referrer()">
<script>
function open_without_referrer(){
var link = encodeURI('{$url}');//url为跳转链接
document.body.appendChild(document.createElement('iframe')).src='javascript:"<script>top.location.replace(\''+link+'\')<\/script>"';
}
</script>
</body>
</html>
2,直接跳转到目标地址,在原窗口打开。
function openWithoutReferrer(url){
document.body.appendChild(document.createElement('iframe')).src='javascript:"<script>top.location.replace(\''+url+'\')<\/script>"';
}
3,直接跳转到目标地址,在新窗口打开。
function openWithoutReferrer(url){
window.open('javascript:window.name;', '<script>location.replace("'+url+'")<\/script>');
}
如果要避免各种原因出现的缓存导致错误,我们在跳转时候加入当前时间。
function openWithoutReferrer(url){
var oDate = new Date();
window.open('javascript:window.name', '<script>location.replace("'+url+'")<\/script>'+oDate.getTime());
}
以上方法通过服务的PHP 验证通过。
php获取referrer的 服务器变量为 $_SERVER['HTTP_REFERER']。