JavaScript [removed] does not set referer in the request header

前端 未结 5 1377
再見小時候
再見小時候 2020-11-30 01:26

I understand relying on Referer in the request header is not right. But my question is, why IE does not set Referer to the Request Header if I use window.location

5条回答
  •  佛祖请我去吃肉
    2020-11-30 01:44

    Setting window.location is not the same as following a link on that page. It starts a new request for the page as thought the user typed the URL into the browser's address bar.

    I did manage to locate a workaround:

    function goTo(url)
    {
        var a = document.createElement("a");
        if(!a.click) //for IE
        {
             window.location = url;
             return;
        }
        a.setAttribute("href", url);
        a.style.display = "none";
        document.body.appendChild(a);
        a.click();
    }
    

    It creates a link on the page and simulates a click. The result is a change in window.location and the referrer is populated.

    http://ianso.blogspot.com/2006/01/referer-header-not-set-on-http.html

提交回复
热议问题