How to open a new tab with javascript?

Asked

Viewed 923 times

0

Hello! I have that function here:
function mostrar(id){ window.location = "visualizar.php?id=" + id;}

That I call when the user clicks on a <a href="javascript:mostrar(id)" target="_blank"></a>

And I want me to open a new tab and not close the current tab.(No tab, like a pop-up) but it looks like the target="_blank" is not working as usual. There is something to do in the javascript function to do this?

  • 1

    and what’s wrong with putting the url in the href attribute?

  • The code is a little more complex than that

  • More complex than: <a href="visualizar.php?id=5" target="_blank"></a> Or using php variables: <a href="visualizar.php?id=$id" target="_blank"></a>

  • It’s just that there’s a database query, but I’ll try to simplify it this way

  • A good, should talk about it, because you made it very clear that you are having trouble opening a new tab with Javascript, in a link <a>, did not specify anything else!

  • Wow, you could really simplify hahahah. Thanks friend!

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.