Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ben Os
20,008 Pointsdocument.referrer and document.location difference?
What is the emphasis of difference between document.referrer and document.location in Javascript.
Wasn't quite clear to me from MDN besides one resembles URI and the second, URL (maybe also accepts methods).
1 Answer
Juthawong Naisanguansee
Full Stack JavaScript Techdegree Graduate 80,724 PointsHello Ben,
Document Referrer Return A URL of Page Before Redirect To This Page. For Example :
You Start with Page http://example.com/ and Click The Link To Your Website or Embed Your Website in The Iframe : http://bentheexample.com
In Your Website : benthexample.com , The Document Referrer Code Will Return The The URL That Refer To You = http://bentheexample.com
However , The Document Location Will Return Your Current URL :
References :
https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer
https://developer.mozilla.org/en-US/docs/Web/API/Document/location
You can browse around the web and Run This Script on Google Chrome Inspector Console :
For Depth Tutorial about Chrome Inspector Tools Workshop : https://teamtreehouse.com/library/website-optimization/chrome-devtools-basics/the-console-panel-2
To Open a Inspector Console on Google Chrome : Right Click -> Inspect and Click on Console Between The Element and Sources and Paste These Code Below in to console. Document Location
alert(document.location);
Document Referrer
alert(document.referrer);
Thanks.
Ben Os
20,008 PointsBen Os
20,008 PointsHi! I know the console and MDN. I read on document.referrer on MDN but didn't quite understand. You explanation wasn't quite clear to me either so I would thank you for rephrasing it (only the part on document.referrer), maybe with another, more intuitive example. Juthawong Naisanguansee
Juthawong Naisanguansee
Full Stack JavaScript Techdegree Graduate 80,724 PointsJuthawong Naisanguansee
Full Stack JavaScript Techdegree Graduate 80,724 PointsHi Ben Aharoni ,
Document Referrer is like Treehouse Referral Program . It return what URL that bring you to this page.
Ben Os
20,008 PointsBen Os
20,008 PointsI now totally understand the concept, thank you.