JS get the Routing URL address, the equivalent of PHP $_server[' Http_referer '. Methods: Using JS to obtain the routing URL address can accurately judge the true antecedents of the Web page. At present, Baidu Statistics, Google Ads statistics, CNZZ Statistics, are used this method. Anti-Theft chain is also very simple, JS to determine the routing URL if not the site does not show the picture, hehe.
Document.referrer
Note: JS in the referer is referrer is not referer, that is: Document.referrer, do not write wrong, to pay attention to, oh, I also write missing amount.
Cases
The code is as follows |
Copy Code |
<table width=100% cellpadding=0 cellspacing=0 border=0 > <script language= "JavaScript" > Thisurl = document. URL; Thishref = Document.location.href; Thissloc = Self.location.href; Thisdloc = document.location; Strwrite = "<tr><td Valign=top>thisurl: </td><td>[" + Thisurl + "]</td></tr>" Strwrite + = "<tr><td valign=top>thishref: </td><td>[" + thishref + "]</td></tr>" Strwrite + = "<tr><td Valign=top>thissloc: </td><td>[" + Thissloc + "]</td></tr>" Strwrite + = "<tr><td Valign=top>thisdloc: </td><td>[" + Thisdloc + "]</td></tr>" document.write (Strwrite); </script> Thisdloc = document.location; <BR> Thisurl = document. URL; <BR> Thishref = Document.location.href; <BR> Thissloc = self.location.href;<br> <script language= "JavaScript" > Thistloc = Top.location.href; Thisploc = parent.document.location; Thisthost = Top.location.hostname; Thishost = Location.hostname; Strwrite = "<tr><td valign=top>thistloc: </td><td>[" + Thistloc + "]</td></tr>" Strwrite + = "<tr><td Valign=top>thisploc: </td><td>[" + Thisploc + "]</td></tr>" Strwrite + = "<tr><td valign=top>thisthost: </td><td>[" + thisthost + "]</td></tr>" Strwrite + = "<tr><td valign=top>thishost: </td><td>[" + thishost + "]</td></tr>" document.write (Strwrite); </script> Thistloc = Top.location.href; <BR> Thisploc = parent.document.location; <BR> Thisthost = Top.location.hostname; <BR> Thishost = location.hostname;<br> <script language= "JavaScript" > Tmphpage = Thishref.split ("/"); Thishpage = tmphpage[Tmphpage.length-1]; Tmpupage = Thisurl.split ("/"); Thisupage = tmpupage[Tmpupage.length-1]; Strwrite = "<tr><td valign=top>thishpage: </td><td>[" + thishpage + "]</td></tr>" Strwrite + = "<tr><td valign=top>thisupage: </td><td>[" + thisupage + "]</td></tr>" document.write (Strwrite); </script><tr><td> |
The way to get JS the current URL method also say, get the current page URL, including the protocol, domain name, folder, file name and complete query parameters.
Window.location.href
Solve IE and FF get referer in IE with JavaScript to do jump, such as with window.location.href = ""; Google cannot access the HTTP referrer requested by the browser if it uses document.referrer because IE empties
and other mainstream browsers Firefox and Chrome will retain referrer, no way, which means that IE also enjoy the "ministerial" special treatment:
The following code solves this problem with IE:
The code is as follows |
Copy Code |
Detect if it is IE browser, then manually add a Referer 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; }
|
This principle is to the Internet Explorer page secretly added a link, and then automatically point to this link, so referrer can retain