Skip to content
WJunction - Webmaster Forum

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

Status
Not open for further replies.
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.

About the author

kaizer01
Active Member · Joined
N.E.E.T. Gaming, Blogging, Girls
1,131
Messages
172
Reactions
63
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom