Javascript void (0) problem in IE

Hi

I am developing a webpage using asp.net.

I use some links on my web page. For this, I used some code like this.

<a href="javascript:void(0);" onclick="javascript:ChangeLoc('TEST','');">Test</a>

and in the method ChangeLoc()I wrote an event __doPostBack.

This works fine in IE7 installed on my machine. But in IE6 on another computer, it does not raise an event __doPostBack.

Edit

When I change void (0) in href, it works fine.

I would like to know if this is a bug with IE or a JavaScript problem.

function ChangeLoc( param, arg )
{
     __doPostBack ( param, arg )
}
+3
source share
4 answers

href and onclick both fire when an element is clicked, you overwrite the onclick event with void ()

change to

<a href="#" onclick="ChangeLoc();return false">test</a>

or with jQuery.

$(function(){
  $("#linkId").click(function(event){
      ChangeLoc();
      event.preventDefault();
  });
}); 
+12

? , IE6? ChangeLoc()? , , :

<a href="#" onclick="ChangeLoc(); return false;">Test</a>

: 'javascript:' onclick

+3

javascript:

<a href="index.html" id="chngLink">test</a>

<script type="text/javascript">
document.getElementById("chngLink").onclick = function(e) {
    if (e && e.preventDefault) {
        e.preventDefault();
    }
    ChangeLoc('TEST','');
    return false;
};
</script>
+1

<a> - javascript. <span onclick="my_function()" class="looks_like_hyperlink">...</span>

0

Source: https://habr.com/ru/post/1707922/


All Articles