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>

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>

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.