Because the user isn’t actually visiting a URL, something has to be done with the href attribute.
There are 2 options:
- Use href="#"
Not finding a name (anchor link) after the pound, the browser “kicks” the user to the top of the current page, losing the location in the document.
- Use href="javascript:void(0);"
Lets go with second option:
<a onclick="someMethod('userControlName')" href="javascript:void(0);">Click Here</a>
I tried to load user control in someMethod('userControlName'). It was working in IE7 and Firefox but not on IE6.
After investing into it a little bit, I found out a simple solution:
><a onclick="someMethod('userControlName'); return false;" href="javascript:void(0);">Click Here</a>
“return false” stops any other action after the person has finished the onClick action. This prevented event bubbling action (For excellent article on Event bubbling, see quirksmode.org )
No comments:
Post a Comment