Access event to call preventdefault from custom function originating from onclick attribute of tag

前端 未结 11 2602
粉色の甜心
粉色の甜心 2020-11-28 04:07

I have links like this:

click
c         


        
11条回答
  •  眼角桃花
    2020-11-28 04:25

    Without any JS library or jQuery. To open a nice popup window if possible. Fails safely to normal link open.

    ...
    

    And the helper function:

    function openNewWindow(event, location) {
      if (event.preventDefault && event.stopImmediatePropagation) { 
        event.preventDefault(); 
        event.stopImmediatePropagation(); 
      } else {
        event.returnValue = false; 
      }
      window.open(location, 'targetWindow', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=450');
    }
    

提交回复
热议问题