The problem is that inline handlers are executed in the context of the HTML element.
that is, everything that is used is first searched in the html element, and in this case href is a property of the a element, not a function.
You can check it simply by changing the code for the next
<a id="aaa" onclick="console.log(this.href===href, href);" href="#">ΠΠ°ΠΆΠΌΠΈ ΠΌΠ΅Π½Ρ</a>
To fix it, just change the name of the handler function:
<script language="JavaScript"> function func() { console.log('Ρ Π΄Π΅Π»Π°Ρ ΡΠ΅Π΄ΠΈΡΠ΅ΠΊΡ'); document.location.href = 'http://stackoverflow.com' } </script> <a id="aaa" onclick="func();" href="#">ΠΠ°ΠΆΠΌΠΈ ΠΌΠ΅Π½Ρ</a>
Or hang the handler using the addEventListener function
function func() { console.log('Ρ Π΄Π΅Π»Π°Ρ ΡΠ΅Π΄ΠΈΡΠ΅ΠΊΡ'); document.location.href = 'http://stackoverflow.com' } document.getElementById('aaa').addEventListener('click', func);
<a id="aaa" href="#">ΠΠ°ΠΆΠΌΠΈ ΠΌΠ΅Π½Ρ</a>