Detect right click's “open in new tab” on link in jQuery? RRS feed

  • Question

  • User-1634604574 posted

    i have this link i want when i right clicked on this link open new tab

    <a href="" id="help">ok</a>

    i wrote this code but is not working

    $('#help').on('click contextmenu', "a", function(event) {
    $(this).attr('target', '_blank');


    Thursday, July 4, 2019 8:45 AM

All replies

  • User753101303 posted


    #test being already your link, I would try without the "a" selector: $('#help').on('click contextmenu', function(event) {
    $(this).attr('target', '_blank');

    Make sure not keeping in user in contorl of the context menu is your best option (using target as part of your markup is not enough ?)

    Thursday, July 4, 2019 9:23 AM
  • User288213138 posted

    Hi zhyanadil,

    According to your description, I couldn’t understand your requirement clearly.

    Is your question “$(this).attr('target', '_blank');” not executed?

    And do you mean right click to execute this code, or right click and click open new table to execute this code?

    If I misunderstand your requirement, please post more details information about your requirement.

    Best Regard,

    Friday, July 5, 2019 9:17 AM