Javascript Get Website URL

There are several ways you can do this, but one way might be best for certain situations (e.g. within an iFrame).

Protocol + Domain + Page

document.URL
> "http://example.com/page1.html"

document.location.href
> "http://example.com/page1.html"

Protocol + Domain

document.location.origin
> "http://example.com"

Domain

document.location.host
> "example.com"

Page

document.location.pathname
> "/page1.html"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)