Loop through all frames on a page, and change the location of all frames to "java2s.com":
Click the button to loop through the frames on this page, and change the location of every frame to "java2s.com".
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <br><br> <iframe src="https://www.java2s.com"></iframe> <iframe src="https://www.bbc.com"></iframe> <iframe src="https://www.nytimes.com"></iframe> <script> function myFunction() {// w w w . j a v a 2 s. co m var frames = window.frames; var i; for (i = 0; i < frames.length; i++) { frames[i].location = "https://www.java2s.com"; } } </script> </body> </html>