The term homepage
itself is a fairly vague construct and not something that is technically identifiable. You could have several different landing pages depending on your screen size, device, credentials, browser, date/time, geolocation, etc. etc.
The only way you can ensure you are on one of these landing pages is to be in control during the initial GET
request to the domain (e.g. http://www.example.com
).
So, if you're already on the page, there's no real way to know how you got there and if this is the default page provided from that domain, though there are hacks you could try to get a general (albeit very error-prone) idea.
For example, you could compile a list of common homepage paths:
var homepages = [ '/', 'index.html', 'index.htm', 'index.php', 'main.html', 'main.htm', 'homepage.html', 'index2.htm' ];
Then compare to the provided window.location.pathname
:
if (homepages.indexOf(window.location.pathname) >= 0) {
// we might be on a "homepage"
}