简体   繁体   中英

Set focus on Iframe Input field onload

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();
};

ps 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

In this case conntentWindow 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM