How to disable the 'Open Link in New Tab' in the browser?

前端 未结 4 1649
攒了一身酷
攒了一身酷 2021-02-05 16:16

How do I disable/remove the \'Open Link in New Tab\' option in the right-click menu of the browser? If this is not possible with javascript etc then is there a way to modify wh

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-05 16:59

    2019

    I'll highlight 2 important comments:

    1. nnnnnn @ Aug 10 '11 at 5:49 :

      As a user I would prefer that type of feature be triggered from a button rather than a link. I expect links to work in a more standard way including giving me the option to right-click for the menu or to middle-click to open directly in a new tab.

    2. Pars @ Dec 21 '13 at 13:10 :

      this wont work when you click by mouse middle button or hold CTRL and click on a link. how to those cases.

    It's up to the browser to decide whether it gets the link-behavior or not.

    Some modern browser (like Chrome) will consider it a link if all the below conditions matches:

    1. It's an ... tag (not span, div, button, etc).
    2. It has href attribute.
    3. href attribute is not empty.

    The below will get the link-behavior:

    Click Here
    

    The below will NOT get the link-behavior:

    Not link because no href
    Not link because empty href
    Not link because not "a" tag
    Not link because not "a" tag again
    

    Important Note:

    Again, it's up to the browser to decide. Some old/stupid browsers may give it link-behavior if ANY of the 3 conditions above matches!

    Conclusion

    If it's a link then use .... If it's not a link then use something else, like

提交回复
热议问题