Pregunta

heres the code of my link confirmation to another tab:

<a href="linksite" onclick="linktab()" target="_tab">Go to link</a>

 <script type'text/javascript'>
       function linktab()
       {
        return confirm('Are you sure you want to go to the link?');
       };
       </script>

i think the problem is the Target=TAB but i dont know how would i do that without closing the other site for loading purposes.

¿Fue útil?

Solución

Instead of onload="linktab()" use onclick="return linktab()

Otros consejos

Just remove target='_tab' and in the confirmation you can do

if(confirm('sure?')){var win=window.open(url, '_blank');win.focus();}

You can study more from this question, very interesting! open-url-in-new-tab-using-javascript

You want to use onclick, not onload.

You also must make sure that your onclick itself returns the value returned from the function:

 onclick="return linktab()"

Otherwise your onclick will just invoke a function, but disregard what it returns.

Demo

Note that valid values for target are*:

  • Any string, with the following restrictions:
    • must not start with a "_" character
    • must be at least one character long
  • any case-insensitive match for one of the following literal strings: "_blank", "_self", "_parent", or "_top".
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top