简体   繁体   中英

how do i open link from array in new tab using java script?

I am getting RSS feed in a javascript array and show in HTML list. but I want that when the user clicks on the link it must be open in a new tab.

//HTML

<ol class="list">
</ol>

//Java script

<script>    


$(function() {
    getRssFeed("https://amirtariq69.blogspot.com/feeds/posts/default?alt=rss", mapFeed);

});


function getRssFeed(url, callback) {
    return feednami.loadGoogleFormat(encodeURI(url), callback);
}

function mapFeed(result) {
    if (result.error) {
      console.log(result.error)
  } else {
        createCarouselList(result.feed.entries.slice(0, 5));
        createFeedList(result.feed.entries.slice(0, 10));
  }
}


function createCarouselList(elements) {
    var list = [];
    $(elements).each(function(index, element) {
        list.push("<li><h3><a href='"+ element.link +"'>"+ element.title +"</a></h3><p>"+ new Date(element.publishedDate).toLocaleDateString("pt-BR") +"</p><span class='carousel-footer'>"+ (index + 1) +" out of 5</span></li>");
    });

    $(".carousel").append(list);

}


// Edit this function please ...
function createFeedList(elements) {
    var list = [];
    $(elements).each(function(index, element) {
        list.push("<li><a href='"+ element.link +"'>"+ element.title + "&nbsp; ["+ new Date(element.publishedDate).toLocaleDateString("pt-BR") +"] "+"</a></li>");
    });
    $(".list").append(list);
    returnCarouselList();
}

    </script>

where I mention editing function can anyone make this list to (open in new tab) list.

添加到标签:

target="_blank"

Solved

function createFeedList(elements) {
    var list = [];
    $(elements).each(function(index, element) {
        list.push("<li><a href='"+ element.link + "' target='_blank +'>"+ element.title + "&nbsp; ["+ new Date(element.publishedDate).toLocaleDateString("pt-BR") +"] "+"</a></li>");
    });
    $(".list").append(list);
    returnCarouselList();
}
``````````````````````

try adding the target attribute target="_blank"> as seen bellow

 <script> $(function() { getRssFeed("https://amirtariq69.blogspot.com/feeds/posts/default?alt=rss", mapFeed); }); function getRssFeed(url, callback) { return feednami.loadGoogleFormat(encodeURI(url), callback); } function mapFeed(result) { if (result.error) { console.log(result.error) } else { createCarouselList(result.feed.entries.slice(0, 5)); createFeedList(result.feed.entries.slice(0, 10)); } } function createCarouselList(elements) { var list = []; $(elements).each(function(index, element) { list.push("<li><h3><a href='"+ element.link +"target="_blank">"+ element.title +"</a></h3><p>"+ new Date(element.publishedDate).toLocaleDateString("pt-BR") +"</p><span class='carousel-footer'>"+ (index + 1) +" out of 5</span></li>"); }); $(".carousel").append(list); } // Edit this function please ... function createFeedList(elements) { var list = []; $(elements).each(function(index, element) { list.push("<li><a href='"+ element.link +" target="_blank">"+ element.title + "&nbsp; ["+ new Date(element.publishedDate).toLocaleDateString("pt-BR") +"] "+"</a></li>"); }); $(".list").append(list); returnCarouselList(); } </script> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM