该链接也在窗口以及弹出窗口中打开

时间:2018-07-24 13:12:13

标签: javascript

def mark_as_open
  update_status(:open, log: false, reset_approval_status: true) do
    if @servicing.redone
      update_redo_reason
      @servicing.paper_trail.save_with_version
    end
  end
end

def info_for_paper_trail
  {
    responsible_id: current_user.id,
    event_name: action_name,
  }
end

//我正在尝试弹出单击的链接,但是单击它的页面也在改变。如何防止其更改?

1 个答案:

答案 0 :(得分:1)

使用preventDefault()可以阻止单击时触发正常事件行为:

    window.onclick = function(e) { var url = e.target;
    windowObjectReference = window.open(
        url,
        "DescriptiveWindowName",
        "resizable,scrollbars,status"
      );
      e.preventDefault();//just add this line
    };