If the iframe's content is a different domain then you are quite limited as to the amount of JavaScript execute against it. You can learn more about why in this post here https://www.cakemail.com/blog/the-iframe-cross-domain-policy-problem/.
I personally have found using the postMessage API is a useful workaround given the right use case (e.g. you must be able to have code hosted by the iframe content provider to handle the message/s). Which tends to fit my works use case with partner integrations with other software companies.
You can find an example of this approach here:
https://codepen.io/wickdninja/pen/oygwNL?editors=1111
// parent js
console.log('1 - parent');
var iframe = document.getElementById('iframe');
iframe.addEventListener("load", function(event){
console.log('3 - parent on iframe load');
iframe.contentWindow.postMessage('testing','*')
}, false);
iframe.contentWindow.addEventListener('message', function(event){
console.log('recieved message event from child')
console.log(event.data);
});
// parent html
<h1>Parent Frame</h1>
<iframe id="iframe" src="https://s.codepen.io/wickdninja/debug/GGgEKE/DqkDdKzORQXk"></iframe>
// child js
console.log('2 - child');
window.addEventListener('message', function(event){
console.log('4 - on child message')
console.log('child postMessage with * origin')
}, false);
window.parent.postMessage('test from child', '*')
// child html
<h1>Child Frame</h1>
// console output from parent
"1 - parent"
"3 - parent on iframe load"
"recieved message event from child"
"testing"