0

I try to parse an URL in angular this way:

var l = document.createElement("a");
l.href='www.example.com';
console.log(l.hostname); // -> '127.0.0.1'

But the log gives me the localhost. Any ideas why that's the case or better ways how to do it?

1
  • 1
    protocol is missing in the href so falls back to parent document host. Commented May 14, 2015 at 21:51

1 Answer 1

1

You should use an absolute url with protocol:

l.href='http://www.example.com';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.