Javascript – Trying to figure out how to resolve IE’s document.frames[“someframe”].function in Chrome

google-chromeinternet explorerjavascriptjquery

I have some code that works in IE.

try{
   top.document.frames["myFrame"].compare();
}catch(err){
   alert("This is not executed.");
}

which doesn't work in Chrome. How should i resolve it? I was thinking that you could do some thing such as

top.document.frames["myFrame"].compare() || /*google chrome variant*/ ;

Thanks gang! 🙂

Oh, what i am doing is selecting the frame "myFrame" and executing a function inside of said frame.

Edit: Added jQuery as a tag because there might be a way to do it that way as well

Edit: – the caught error in my example is:

TypeError:  Cannot read property of "myFrame" of undefined

Best Answer

The standard way to do that is this one:

window.frames["yourFrame"].yourFunction();