JavaScript document.referrer query source URL

 JavaScript document.referrer belongs to the content of the JavaScript Document object collection. It can be used to query the source URL of the webpage, such as which blog, search engine, news website... .


JavaScript document.referrer syntax example

document.write( document.referrer );


The document.write outside the brackets means that it is displayed on the web page. The red part in the brackets is the key point. If the traffic source is not from other websites, but the netizens open the webpage by themselves (such as directly hitting the URL or from the browser bookmark Straight link), then return null, that is, no value.

JavaScript document.referrer implementation example
<html>
<body>
<script type="text/javascript">
document.write('The traffic source URL is:');
document.write(document.referrer);
</script>
</body>
</html>
As mentioned earlier, if a netizen directly enters the web page by typing a URL, there will be no source website information in the DOM, so no value can be queried using document.referrer. Relatively, as long as it is sent by other When the link to the website is reached, you can query it through the attribute of document.referrer.

Post a Comment

0 Comments