This is the iframe code:
<div id="OutDiv" class="outerdiv">
<iframe src="http://beta.sportsdirect.bg/checkout/onepage/" id="InnerIframe" class="FrameCSS" scrolling="no"></iframe>
</div>
Here is the HTMl code of the button which the iframe above is calling:
<button type="button" id="SuperWebF1" title="Continue" class="button">Continue</button>
Here is the jQuery function that i use to trigger the click of the button when page is loaded:
$('#SuperWebF1').trigger( "click" );
But this is working like that only when i place the jQuery code inside the source of button and the iframe is calling the button with the script.
I want to make an event which is clicking the button from outside the iframe. Is it possible ?
Thanks in advance!
NOTE: .contents() does not work if iframe's src points to cross domain page. More: Cross domain iframe issue and Get DOM content of cross-domain iframe
//execute code after DOM is ready
$(function() {
//find iframe
let iframe = $('#main_iframe');
//find button inside iframe
let button = iframe.contents().find('#main_button');
//trigger button click
button.trigger("click");
});
<!--Add jQuery library-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
If you need to manipulate another page inside iframe, search for official API or GET parameters. Example: Youtube Embed Video, Google Maps Embed Api
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments