JS: redirect with referrer domainname and tld

Had to write this script to redirect visitors of a global information page back to the subdomain of the site they came from. Visitor came from a link on this page: http://www.domain1.tld/category/post Comes on a different website: http://www.domain2.tld/page After clicking the button the visitor is sent to: http://subdomain.domain1.tld/ 1 2 3 4 5 6 7 …