Open links in a new window in instafeed.js

I use instafeed.js to display my latest instagram images on my website. But by default, image links open in one window. This is the JS code: https://github.com/stevenschobert/instafeed.js/blob/master/instafeed.js more info: http://instafeedjs.com

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

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

But this trick does not work in this situation.

Any solution? Thanks.

+7
javascript instafeedjs
source share
3 answers

The best way to do this is to use the template parameter:

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

You do not need to directly modify the source file.

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

+8
source share

I am updating 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(); }); 
+4
source share

Gotcha! Following the logic of Kasra, I found a solution:

In your instafeed.js file, scan line 177 and add anchor.setAttribute('target', '_blank'); . It works great.

0
source share

All Articles