Reputation: 5637
I was wondering if there's an explicit way in JavaScript to tell if a link that is being clicked on a web page is going to send the user to another web page on the site OR send the user to some external site.
Here's a little example of what I mean:
<a href="another_page.html">A link to another page on website</a>
<a href="http://google.com/">A link to an external page from a different website</a>
When one of these links are clicked, is there an explicit way to tell if the url clicked will lead to another page on the current site or some external site?
I am mainly wondering if there's some kind of way JavaScript can tell if a link it external or internal by clicking on it, before the user goes to the page.
Upvotes: 0
Views: 224
Reputation: 2068
you can use
document.location.hostname
will give you location of your own domain and then check whether it is own domain or going somewhere else or check http
Upvotes: 2