Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

249
Vistas
'Open in new tab' click on link not open href value

I am using Vue2 and I have <a> tag with href='#' and @click.prevent="someMethod()".
This is working as expected in a situation when do a left click (it is calling a method), but if I do a right click -> open in new tab, in that case it is opening href value, which is wrong.

Which approach do you suggest in order to also call a @click.prevent="someMethod()" when opening from non-left click situations?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

If you're looking to control the behavior for all clicks, then you'll need to add more than one click event handler.

Something like this. Here's a working JSFiddle of the code.

  <a
    href="#"
    @click.prevent="someMethod()"
    @auxclick.prevent="someMethod()"
    @contextmenu.prevent
  >
    Click Me
  </a>
</div>

@click.prevent handles left click events.

@auxclick.prevent handles auxclick events (i.e. non-left click events).

@contextmenu.prevent disables the context menu that pops up when you right click on the element.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I have keeped anchor link with @click.prevent + added :href='sameMethodAsInClickEvent()' so now, if it will be non-left-click, it will call href and still it will open the right link/method.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You cannot override the native context menu Open in New Tab behavior; it will always open the anchor's href in a new tab.

Your only options are:

  • Prevent the context menu from being shown with @contextmenu.prevent. Not good UX.
  • Prevent the context menu but instead show your own custom context menu with an Open in New Tab item which you can handle yourself.
  • Use a <button>. This was my first thought since you don't really need an anchor here anyway because there's no real link.
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda