2

I want to open a link in new tab using a tag, the html for this looks like :

<a href=""
    onclick="window.open( urlvalue, '_blank' );">MyLink
</a>

How could i implement it using Jquery and Javascript.

Note: This tag is inside a div, so I want to append the a tag inside that div as well.

user2530619
  • 75
  • 2
  • 8

3 Answers3

7

You just need to add like below, and it will work

<a href="URLValue" target="_blank" >My link</a>

Jquery code:-

$(this).find("a").attr("target", "_blank");
Nad
  • 4,605
  • 11
  • 71
  • 160
2

Using jQuery: (Given that there is an <a> element present)

$(function(){
   $('a').attr('target', '_blank').attr('href', 'YOUR_LINK').trigger('click')
});

EDIT

Another case (You have <div> element and you want to append a link inside it);

$(function(){
   $('div').append('<a href = "YOUR_LINK" target = "_blank">LINK</a>');
});
jpcanamaque
  • 1,049
  • 1
  • 8
  • 14
0

If it's Javascript you need... From http://www.pageresource.com/jscript/jwinopen.htm

window.open('URL','WINDOW NAME','width=width,height=height')
Matt Maclennan
  • 1,266
  • 13
  • 40