如果您使用 javascript 将用户重定向到新网页location.href = <url>
,那么目标 Web 服务器会看到什么 REFERER 标头?
问问题
10565 次
3 回答
9
除了一些例外,发送的标头是带有重定向的页面,而不是进行重定向的页面的引用者。这与保留原始引荐来源网址的服务器端重定向相反。
因此,如果访问者从A.html
到B.html
并B.html
触发location.href
重定向到C.html
,则 Web 服务器将B.html
视为引荐来源。(如果您在服务器端进行了从B.html
to的重定向C.html
,A.html
则将是 . 的引用者C.html
。)
旧版本的Internet Explorer将发送一个空白标头,就像(一如既往)从 HTTPS 重定向到 HTTP。
于 2011-04-14T01:23:54.137 回答
4
它会看到它来自的页面,就像点击一个链接一样。
要从任何页面对此进行测试,请重定向到 phpinfo() 页面或任何其他回显标题的页面,例如:
window.location='http://hosting.iptcom.net/phpinfo.php';
(从随机谷歌搜索中提取的页面)
于 2011-04-14T01:24:45.850 回答
3
大多数浏览器会通过 location.href 传递 HTTP_REFFERER,但 IE 在某些情况下不会。
如果推荐人对您来说真的很重要,那么您可以这样做:
function goTo(url) {
var a = document.createElement("a");
if(!a.click) { //Only IE has .click so if it doesnt exist use the simple method where the refferer is passed on other browsers.
location.href = url;
return;
}
a.setAttribute("href", url);
a.style.display = "none";
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(a);
a.click();
}
于 2011-04-14T01:29:56.610 回答