Murli
Murli

Reputation: 1258

Why does anchor tag remove tab character in URL specified inside href attribute?

Anchor tag is removing tab character in URL specified inside href attribute which is calling Javascript function in my case whereas if spaces are present in URL specified inside href attribute it won't remove

Below is the sample piece of code to reproduce it-

<html>
<script>
function test(name)
{
 alert(name+ "is the Name");
}
</script>
<body>
<a href="Javascript:test('Murlidhar	');">Click Me</a>
</body>

</html>

Upvotes: 3

Views: 393

Answers (3)

Alohci
Alohci

Reputation: 82976

When an <a> element is clicked, the link is followed and its URL is resolved. This causes the string to be processed by the basic URL parser.

In your example, the parameter is processed in the path state during which TAB (U+0009) characters, along with carriage return and line feed characters, are ignored, and therefore do not form part of the resolved URL.

Only then is the resolved URL evaluated, the "javascript:" scheme recognised and the remainder handed off to the script engine for processing.

Upvotes: 3

Like Boldewyn said. URI's Don't accept whitespaces. try \t to have space after the name in text().

Upvotes: 0

Boldewyn
Boldewyn

Reputation: 82734

The content of an href attribute is always an URI. URIs do not allow whitespace, so the browser strips it. You can overcome this problem by %-encoding the tab (and any other spaces):

Space -> %20
Tab -> %09
Line feed (\n) -> %0A

Upvotes: 4

Related Questions