Reputation: 409
//prevent default handler
function click_handler(event){
if(event.shiftKey){
event.preventDefault();
}
}
//event listener
var file_mgmt=document.querySelector('div.filemanager');
if(window.addEventListener){
file_mgmt.addEventListener('click',click_handler,false);
}else if(window.attachEvent){
file_mgmt.attachEvent('onclick',click_handler);
}else{
file_mgmt.onclick=click_handler;
}
basically file_mgmt is a div container which is enclosed with tag linking to another links. Since Shift+click opens the link in new _blank tab i want to prevent it since it will damage the original page layout.
Giving up after a while, i even tried following from Mozilla doc:Event.preventDefault(), the result being the same.
Any Suggestions?
Upvotes: 0
Views: 68
Reputation: 468
Preventing default action when clicking on a div will not do anything since by default it doesn't do anything anyway. You should attach the click handler to the actual link instead.
Upvotes: 1