dombrorj Posted May 1, 2012 Share Posted May 1, 2012 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! Quote Link to comment Share on other sites More sharing options...
.josh Posted May 2, 2012 Share Posted May 2, 2012 <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> Quote Link to comment Share on other sites More sharing options...
dombrorj Posted May 2, 2012 Author Share Posted May 2, 2012 Perfect! Thanks you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.