Best way to get iframe object

We are using too many iframes in our web application. In these iframes we load pages, which can also contain iframes and so on up to level N.

I am currently using a recursive function to find out the required iframe in JavaScript. It works great. The problem is when we create large dynamic pages that can contain up to 1000 iframes. In this case, my recursive function is taking too long to find the required iframe.

How can I overcome this problem, or is this any alternative to recursion in JavaScript.

thanks

+2


a source to share


1 answer


try registering all frames in the array just before loading (while the user is still waiting). This way, you don't have to collect all the frames and only then go through them. at the bottom of the page ...

< /html>
< script>iframes=document.getElementsByTagName("iframe")< /script>

      

Still not quite sure how you define each iframe - so if you are looking for a specific id or src - try this as a setup array



< /html>
< script>
iframes=document.getElementsByTagName("iframe")
var iframe_stuff=[]
var i=0
while(iframes[i])
{
iframe_stuff[i]=[]
iframe_stuff[i]["id"]=iframes[i].id
iframe_stuff[i]["src"]=iframes[i].src
i++
}< /script>

      

So, when you need to go through your iframes, the list array is ready. Also remember to use "break" after you find the desired iframe. If your found iframe is at number 4, break will stop searching there and not check the rest ...

+1


a source







All Articles