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!

Link to comment
Share on other sites

<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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.