I have an array of URLs, for example:
var urls = ["http://www.getbootstrap.com","http://www.reddit.com","http://www.bbc.com/news","http://www.google.com"];
and I have an iframe:
<iframe></iframe>
and two links:
<a href="#" id="forwards">Forwards</a> <a href="#" id="backwards">Backwards</a>
What I am trying to do is link it up so that the <iframe> shows the first URL in the array, and when you click either forwards or backwards it changes the src attribute to either the next url or the previous url. Also, when it is at the begining or end of the array then clicking the buttons should take it to the end or begining of the array, respectivly. I have this:
$('#forwards').click(function(){
current++;
$('iframe')[0].src = urls[current];
});
and the same to go backwards, but it is very inefficient, and doesn't work when you get to either end of the array. Is there a better way to do it?
iframeto be a variable