Jump to content

Javascript Iframe Array with Next Button


dombrorj

Recommended Posts

I'm using the following javascript code to load contents of an iframe. When the user clicks the "next" button, the contents of the iframe loads the next item in the array. Works great.

 

What I'd like to do is have the script cycle through the items of the array. When it has gone through every item, it then redirects the parent window to a new URL. Do you know how I can implement that?

 

Here's the code...

 

<script>
var urls =new Array('http://cvs.com','http://target.com','http://walgreens.com');
I=0;
function next()
{
I-=1;
if(I==-1)I=urls.length-1;
window.frames['links'].location.href=urls[i];
}
</script>
</head>

 

 

<iframe src="http://reddit.com" name="links" frameborder="0" height="500px" width="80%" scrolling="no">Iframe Not Supported. Please Use a Different Browser</iframe>
<p align="center"><a href="javascript:next()"><img src="images/next.jpg" width="201" height="65" border="0" /></a></p>

 

Thanks!

<script type='text/javascript'>
var urls = [
  'http://cvs.com',
  'http://target.com',
  'http://walgreens.com'
]

function next() {
  this.c = this.c+1 || 0;
  if (typeof urls[c] == 'undefined') 
    window.location='http://somesite.com';
  else 
    window.frames['links'].location.href=urls[c];
}
</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.