Skip to content Skip to sidebar Skip to footer

Auto-click Button In Div On-load

I have a page where I modded an app to prepopulate a number of fields. I would like to automatically have the 'submit' button be pressed/submitted when the page loads. I have tried

Solution 1:

I see that your iframe is in the same domain and hence it will possible for you as the cross-domain security may not apply.

Give your iframe an id. And then:

document.getElementById('iframeName').contentWindow.document.getElementById("buttonid").click()

More info here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#Scripting

Make sure that the DOM is fully loaded before you fire your Javascript. Wrap this code into body load or iframe load.

Update:

If the iframe is in the same domain and is in your control, you don't need to do all this. Just fire the click from domloaded of jQuery, or place your code at the end (just before body ends). It will work.

Seeing your code, you have defined the function in the head and are calling it at body load. Place the function and the call at the end of the body.

Solution 2:

You cannot do it in iframe for security reasons: http://pipwerks.com/2008/11/30/iframes-and-cross-domain-security-part-2/

Solution 3:

Content coming from different domain in iframe can't be controlled in your page using javascript. Browser treats iframe as a different window so you've no access over it. it's something like trying to access content of different window open in your browser from your own window(which is obviously not possible)

Post a Comment for "Auto-click Button In Div On-load"