IE has empty document.referrer after a location.replace

前端 未结 3 1333
眼角桃花
眼角桃花 2020-12-01 09:31

I\'ve got a site that does a complex search and has a \"loading\" page. On the loading page we use:

相关标签:
3条回答
  • 2020-12-01 10:05

    Looks like this is just the cost of doing business with IE users. Can't be fixed without a hack. Working on one now. Thanks for listening.

    http://webbugtrack.blogspot.com/2008/11/bug-421-ie-fails-to-pass-http-referer.html

    I used the workaround to make this function. Works like a charm.

    <script type="text/javascript" >            
    function redirect(url) {
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
            var referLink = document.createElement('a');
            referLink.href = url;
            document.body.appendChild(referLink);
            referLink.click();
        } else {
            location.href = url;
        }
    }
    </script>
    
    0 讨论(0)
  • 2020-12-01 10:12

    Based on Matt answer this code snippet also detects IE11 and opens url in new tab. On Microsoft Edge browser no additional changes are required to pass document.referrer with window.location.replace.

    <script type="text/javascript">
      function openUrlNewTab(url) {
        //use userAgent to detect <IE11 and window obj to detect IE11
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent) || 
           (!!window.MSInputMethodContext && !!document.documentMode)) {
          var el = document.createElement('a');
          el.href = url;
          el.target = '_blank';
          document.body.appendChild(el);
          el.click();
        } else {
          window.open(url);
        }
      }
    </script>
    
    0 讨论(0)
  • 2020-12-01 10:24

    INFO: Internet Explorer Does Not Send Referer Header in Unsecured Situations

    When linking from one document to another in Internet Explorer 4.0 and later, the Referer header will not be sent when the link is from an HTTPS page to a non-HTTPS page. The Referer header also will not be sent when the link is from a non-HTTP(S) protocol, such as file://, to another page.

    Microsoft

    0 讨论(0)
提交回复
热议问题