Search code examples
htmlhrefurlencode

Link doesn't work when href attribute value is url encoded


Why is it that the link doesn't work when href attribute value is url encoded?

Are we not supposed to encode it? Same behavior observed in Chrome & FF

Works

<!DOCTYPE html>
<html>
<body>

<p>Sweet fruit: <a href="http://google.com/search?q=banana">Banana</a></p>

</body>
</html>

Doesn't work

<!DOCTYPE html>
<html>
<body>

<p>Sweet fruit<a href="http%3A%2F%2Fgoogle.com%2Fsearch%3Fq%3Dbanana">Banana</a></p>

</body>
</html>

Solution

  • Its an protected link. this is how the encode works http://www.w3schools.com/tags/ref_urlencode.asp

    this was the link u showed the first one is decoded and the second one encoded .

    http://google.com/search?q=banana http%3A%2F%2Fgoogle.com%2Fsearch%3Fq%3Dbanana

    lets take a look

    In this case the "/" becomes %2F, the "?" a %3F and the "=" %3D

    its an protection and so the link can not be used. the dns cant read it. and as you see the first link is clickable and the second one not.