0

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.

user2609718
  • 21
  • 1
  • 4

3 Answers3

0

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".
David Hedlund
  • 128,221
  • 31
  • 203
  • 222
0

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

Community
  • 1
  • 1
Phong Vo
  • 1,078
  • 7
  • 16
0

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

Arun Bertil
  • 4,598
  • 4
  • 33
  • 59