Possible Duplicate:
Parse URL with Javascript
I want to compare the basic part of the URL. If I’ve entered www.websitename.com it should say duplicate if I enter
http://www.websitename.com
https://www.websitename.com
websitename.com
http://www.websitename.com/filename
subdomain.websitename.com etc..
How can I do it?
If you just want to compare if two URLs have the same domain, you can easily code that with a regular expression.
There is no way for javascript to know that
http://www.websitename.com/andhttp://subdomain.websitename.com/do or don’t resolve to the same host or content without actually fetching the content and comparing it because it totally depends upon the host implementation which can be set either way and isn’t something that javascript can know.Here’s a function that will get the domain from a URL:
You can see what it returns for each of your URLs here: http://jsfiddle.net/jfriend00/6YNgp/