Open hidden LINK in new javascript tab

Asked

Viewed 880 times

2

Through Stackoverflow I got a code that I was looking for, that serves to hide the target link, not to appear when pointing the mouse over the image or video that has the link, but now I need to, when clicking, open a new tab, and do not leave my blog.

The Code is as follows::

<div onclick="javascript:window.location.href = 'http://www.sonoticias8515.com.br/canal/canal/votacao-melhor-gol-da-uefa-champions-league---golaco-do-barcelona-jogo:-barcelona-/2507811a1k5s9h3551638010852a21510855 ';" style="cursor:pointer;text-decoration:underline;">Teste</div>

1 answer

1

When you use window.location.href you are opening a new url on the same page. Since that is not what you want you should use open window.. Then you can wear something like

<div onclick="javascript:window.open('http://www.o.url.que.queres', '_blank');" ...

But it seems to me that you are passing next to the easiest solution. If you do not want the mouse to change over a normal link (<a href="...">Link</a>) you can do it with CSS like this: (jsFiddle).

CSS:

a.nostyle:link {
    text-decoration: inherit;
    color: inherit;
    cursor: default;
}

a.nostyle:visited {
    text-decoration: inherit;
    color: inherit;
    cursor: default;
}

And on the link/anchor you only need to add the class nostyle.

  • 1

    Very good Sergio, solved my problem expensive, as for CSS I did not need, with the code above and implementing with your code window.open I managed to hide the link and when they click it is now opening in new tab. Congratulations and thank you very much!

  • 1

    @I know the code would work what I meant is that you can do the same with CSS and using anchors (<a>). It would be better from the point of view of functionality, semantics and SEO. But use how you feel more confident.

Browser other questions tagged

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