Open LINK hidden in new tab with javascript

2

Through StackOverflow I got a code I was looking for, which serves to hide the destination link, not to appear when I point the mouse over the image or video that has the link, but now I need to click in 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>
    
asked by anonymous 30.07.2015 / 16:25

1 answer

1

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

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

But it seems to me that you are moving alongside the easier solution. If you do not want the mouse to change over a regular link ( <a href="...">Link</a> ) you can do this 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 in the link / anchor you just need to add the class nostyle .

    
30.07.2015 / 16:33