In many cases, we need to change these default actions, such as: When we click on a link, we perform some AJAX operations, but we do not want to perform a jump action, so we have this article: block browser default action.
In fact, this is not a very difficult topic, the reason for the individual to take out the browser compatibility problem:
Copy Code code as follows:
<script type= "Text/javascript" >
Description: Block browser default actions in Javascript
Author: John Resig
function Stopdefault (e) {
Prevent the default browser action (the consortium)
if (e && e.preventdefault)
E.preventdefault ();
A shortcut for stoping the browser action in IE
Else
Window.event.returnValue = false;
return false;
}
</script>
Use examples:
cloud-dwelling community <script type= "Text/javascript" > var test = document.get Elementbyid (' Testlink '); Test.onclick = function (e) {alert (' My link address is: ' + This.href + ', but I will not jump.) '); Stopdefault (e); } function Stopdefault (e) {//Prevent the default browser action (All--) if (e && e.preventdefault) e.preve Ntdefault (); A shortcut for stoping the browser action in IE else Window.event.returnValue = false; return false; } </script>
[ctrl+a All selected note: If you need to introduce external JS need to refresh to perform]