开发者

Best way to get the iframe object

We are using too many iframes in out web application. In t开发者_Python百科hese iframes we load the pages which may also contains iframes and so on up to N level.

Right now i'm using recursive function to find out the required iframe object in JavaScript. It works fine, The issue is when we create large dynamic pages which may contains up to 1000 iframes in it. In this case my recursive function takes too much time to find the required iframe object.

How i can overcome this issue or these is any alternative of recursion in JavaScript.

Thanks


try registering all the iframes into an array immediately before onload (while the user is still waiting). This way you dont have to assemble all the iframes and only then go thru them. at the bottom of your page...

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

Still not really sure how you are identifying each iframe - so if you are searching for a particular 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 thru your iframes the list array is ready. Also remember to use 'break' after you found the iframe you want. If your found iframe is at number 4, break will stop the search there and not check the rest...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜