Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open links in new window in instafeed.js

I am using instafeed.js to show my latest instagram images in my website. But by default, image links are opened in same window. This is the JS code: https://github.com/stevenschobert/instafeed.js/blob/master/instafeed.js more information: http://instafeedjs.com

I tried to open links in a new window by using this trick:

<script>
$(function(){
  $("#instafeed a").attr("target","_blank");
});
</script>

But this trick is not working in this situation.

Any Solution? Thanks.

like image 445
Kasra Avatar asked Jun 17 '14 11:06

Kasra


2 Answers

The best way to do it, would be to use the template option:

var feed = new Instafeed({
  template: '<a href="{{link}}" target="_blank"><img src="{{image}}" /></a>'
  // other settings...
});

You shouldn't need to modify the source file directly.

For more information on how templates work, check the documentation on templating.

like image 175
Steven Schobert Avatar answered Oct 04 '22 19:10

Steven Schobert


I update the links in the after function

jQuery(document).ready(function($){
  var loadButton = $('#load-more');
  var feed = new Instafeed({
    get: 'user',
    userId: xxx,
    accessToken: 'xxxx',
    limit:160,
    after: function() {
      $("#instafeed a").attr("target","_blank");
      // disable button if no more results to load
      if (!this.hasNext()) {
        loadButton.attr('disabled', 'disabled');
      }
    }
  });    

  $('#load-more').on('click', function() {
    feed.next();
  });
  feed.run();
});
like image 31
Mat Kay Avatar answered Oct 04 '22 21:10

Mat Kay