Reputation: 681
I am trying to set a focus on an input field inside an iframe onload. The iframe does not have an id or class so I used tag for getting the element but when i do this I am getting an error "TypeError: Cannot read property 'getElementById' of undefined at window.onload "
window.onload = function() {
document.getElementsByTagName('iframe').contentWindow.document.getElementById("form_002b_fld_0_fn").focus();
};
p.s. only option to put the script is on the header and I am not allowed to edit the input box to add autofocus since its a form generator without html code
Upvotes: 1
Views: 1793
Reputation: 13077
In this case contentWindow
is undefined, as you don't have access to an iFrame with content from another domain.
The only way to get this to work is to ask the owner of the form building app you're using to do this for you.
Upvotes: 2