Jump to content

Loop through frame sources, but only continue on action


coldfission

Recommended Posts

This code will loop through the pages array and send them to the iframe. Once the page is loaded, it continues onto the next page source. This is similar to what i want, But I don't want the page to reload to the next one until the user reaches a certain point on that page source. This is because each individual page prompts the user to enter information. After the user enters their information, i want it to continue on to the next page source. How do i do this?

 

<html>
<head>
<script type="text/javascript">

var pages = [];
pages[0] = "http://www.blahblah.com/blah";
pages[1] = "http://www.blahblah.com/blahblah";

function updateFrame() {
// get the frame
var frame = document.getElementById("loopingFrame");

if(!pages[frame.pageIndex]) {
	// first iteration -- initialize the properties
    	frame.pageIndex = 0;
    	frame.count = 1;
    }
    else if(pages.length <= (parseInt(frame.pageIndex)+1)) {
    	frame.pageIndex = 0;
    	// we've gone through all the pages this time, increment count
    	frame.count++;
    }
    else {
    	// no need for a new number, just a new base page
    	frame.pageIndex++;
    }

    var pageIndex = frame.pageIndex;
var i = frame.count;

frame.src = pages[pageIndex] + i;

}
</script>
</head>
<body>
<iframe id="loopingFrame" src="http://www.blahblah.com/blah" onload="updateFrame();">        
</iframe>
</body>
</html>

Link to comment
Share on other sites

Do you mean that, in the iframe, every time the user activates a certain input, the page will go to the next page in the array? if so, something like this should work:

<script type="text/javascript">
var pages = [];
pages[0] = "http://www.blahblah.com/blah";
pages[1] = "http://www.blahblah.com/blahblah";
var index = 0;
function nextPage()
{
   var frame = document.getElementById("loopingFrame");
   frame.src = pages[index];
   index++;
}
</script>
<button onClick="nextPage()">Next Page</button>

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.