[javascript] how to break/stop code if statement met on loop?

Status
Not open for further replies.

kaizer01

Active Member
1,131
2011
172
720
Hi

how to break/stop code if statement met on loop?
for example insde https://google.com/update.php?id=2 the page shows or output a text "Can't Update" and the loop for openNext() will stop?
it won't load the next array

Thanks


Code:
<iframe id='the_iframe'></iframe>

<script>
   
    var urls = [
'https://google.com/update.php?id=1',
'https://google.com/update.php?id=2',
'https://google.com/update.php?id=3',
'https://google.com/update.php?id=4'


];
function openNext(){
    document.getElementById('the_iframe').src = urls.shift();
    if(urls.length)setTimeout('openNext()',3000);
}
openNext();
</script>
 
Last edited:
4 comments
If the condition is dependent on the contents of the iframe'd page you can't unless the iframe'd page has the same origin as the page containing the iframe. This prevents things like XSS attacks.

 
it has the same origin
what do you think is the best approach for this one?

edit: I just got the code in the StackOverflow, i think i'll just write it using php which is easier.

Thanks
 
Last edited:
Status
Not open for further replies.
Back
Top