Reputation: 1258
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
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
Reputation: 17
Like Boldewyn said. URI's Don't accept whitespaces. try \t
to have space after the name in text()
.
Upvotes: 0
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