HTTP Referrer and IE7 and IE8

扶醉桌前 提交于 2019-12-23 08:36:40

问题


Hi i've tried the following to find the referrer in MSIE / IE7 and IE8 but its returning blank each time;

PHP:

<?
echo $_SERVER['HTTP_REFERER'];
?>

JAVASCRIPT:

document.write('Thanks for visiting from ' + document.referrer);

Does any know what the issue could be I'm referering using document.location from a page on another domain and work fine with all other browsers minus MSIE.

Any help would be great!


回答1:


The HTTP Referer header is not required by the HTTP Protocol :

  • It is only sent as an information
  • The browser can, or cannot, send it (Which would explain why you're getting it with some browsers, and not getting it with some others)
  • Some firewall / security software could remove it, I suppose, in some situations (I've seen that, some years ago, if I remember correctly)
  • It can be forged easily by the user

Which means that you cannot rely on the Referer for your application : you can use it to provide some additionnal functionnality, but your application must work even if it's not there, or not correct.




回答2:


HTTP_REFERRER does't work in IE browser it works fine for all browsers like mozilla, safari, opera etc... Referrer method doesn't recognize in IE it will return null when we apply it for IE. Actually using HTTP_REFERRER itself is not a right criteria because we can't expect it will work or not as it is not a standard HTTP HEADER.




回答3:


Here's a hack you might try:

    var referLink = document.createElement('<a href="' + theUrl + '" target="' + theWindow + '"></a>');
    document.body.appendChild(referLink);
    referLink.click();


来源:https://stackoverflow.com/questions/2460490/http-referrer-and-ie7-and-ie8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!