Find iFrame by ID

Another way to work with iFrames is to find the index by the ID attribute of the iFrame. Assuming each iFrame has an ID we can search for, or at least the one we are looking for, we can use the sample code below to determine the index of the frame itself, making it easier to use the index in the target window for other actions.

After this script runs, the debug alert window shows the iFrame index we were looking for. So if the index is 7, the target window we use is now gomez_top[0].frames[7].

var iFrames = document.getElementsByTagName("iframe");
for(var i = 0; i < iFrames.length; i++)
{
	alert (i + " " + iFrames[i].getAttribute(['id']));
	if (iFrames[i].getAttribute(['id']) == 'centerIFrame')
	{
		alert ("Main Frame Index: " + i);
	}
}