如何在新标签中打开链接?

时间:2017-05-26 06:00:51

标签: javascript jquery

如何在新标签页中打开这些链接,而不是在我的网站标签页上打开?

recentItems

for(var i in plinks){         var plink = plinks [i];

$(document).ready(function() {
var plinks = [
    {
        name: 'ady',
        plink: 'http://steamcommunity.com/id/42432'
    },
    {
        name: 'moon',
        plink: 'http://steamcommunity.com/id/22242'
    },
    {
        name: 'internal',
        plink: 'http://steamcommunity.com/id/2424'
    },
    {   name: 'silvatone',
        plink: 'http://steamcommunity.com/id/4324234'

    },
];

3 个答案:

答案 0 :(得分:0)

您可以使用window.open

来完成

<强> CODE

 $(document).ready(function(){
    var plinks = [
    {
    name: 'ady',
    plink: 'http://steamcommunity.com/id/42432'
    },
    {
    name: 'moon',
    plink: 'http://steamcommunity.com/id/22242'
    },
    {
     name: 'internal',
    plink: 'http://steamcommunity.com/id/2424'
    },
    {   
    name: 'silvatone',
    plink: 'http://steamcommunity.com/id/4324234'
    },
   ];
   for(var i=0;i<plinks.length;i++){
      window.open(plinks[i]['plink'],'_blank')
   }
}) 

答案 1 :(得分:0)

在追加a tag

上添加target="_blank"

使用Array#mapArray#join()方法

形成更简化的版本.DO
  var res = plinks.map(function(a) { 
           return '<a href="' + a.plink + '"  target="_blank">' + a.name + '</a>';
            })
            $('#marquee').append(res.join('-'))

$(document).ready(function() {
      var plinks = [{
        name: 'ady',
        plink: 'http://steamcommunity.com/id/42432'
      }, {
        name: 'moon',
        plink: 'http://steamcommunity.com/id/22242'
      }, {
        name: 'internal',
        plink: 'http://steamcommunity.com/id/2424'
      }, {
        name: 'silvatone',
        plink: 'http://steamcommunity.com/id/4324234'
      }, ];
      
      for (var i in plinks) {
        var plink = plinks[i];

        $('#marquee').append('<a href="' + plink.plink + '"  target="_blank">' + plink.name + '</a>');

        var plink = $('#marquee').children('a').last();

        if (i != plinks.length - 1) {
          $('#marquee').append(' - ');
        }
      }
      })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="marquee"></p>

答案 2 :(得分:0)

在锚标记中添加target=_blank

E.g。

<a target="_blank">