在javascript函数中模拟href单击?

M S*_*ach 3 javascript href javascript-events java-ee

我在jsp的遗留项目中有以下代码

   <tr>
    <th colspan="2">Customer</th>
    <td colspan="2">
      <a href="myAction.do" target="view">CustomerLink</a></td>
  </tr>
Run Code Online (Sandbox Code Playgroud)

当我们点击CustomerLink时,我希望对行为进行少许修改.我只想在点击动作之前在javascript函数中进行一些处理.我没有得到如何模拟javascript函数中的href链接行为?

我试过的: -

 <tr>
    <th colspan="2">Customer</th>
    <td colspan="2">
      <a href="javascript:customerLinkClicked('myAction.do')" target="view">CustomerLink</a></td>
 </tr>
Run Code Online (Sandbox Code Playgroud)

// javascript函数

    function customerLinkClicked(path)
    {

        // simulate the href link behaviour, not sure how to do this


    }
Run Code Online (Sandbox Code Playgroud)

y34*_*34h 6

<a href="javascript:customerLinkClicked('myAction.do')" target="view">CustomerLink</a>
<script>
    function customerLinkClicked(path) {
        if (confirm('message'))
            document.location.href = path;
    }
</script>
Run Code Online (Sandbox Code Playgroud)