0

I'm having to use a series of iframes containing PayPal 'Buy Now' buttons.

For aesthetic reasons, I want to use a different PayPal button design. As such I have placed my new design over the iframes 'Buy Now' link using CSS absolute positioning. Using jQuery I want a click on this new image to trigger the PayPal iframe button.

There are multiple PayPal buttons on the page so I just want the nearest iframe to be triggered when an image is clicked.

My jQuery codes event is working (I can see the console log output when clicked), however, it's not triggering the iframes button as planned.

/*PayPal Buy Now Button Activation*/
$('.paypal-paynow img').click(function(event) {
  console.log('iFrame doohicky');
  $(event.target).closest("iframe").click();
});
<div class="paypal-paynow btn1">
  <img src="https://foo.com/new-paypal-image" alt="Pay Now Button">
  <iframe scrolling="no" src="https://foo.com/dev/product/iframepage1/"></iframe>
</div>

<div class="paypal-paynow btn2">
  <img src="https://foo.com/new-paypal-image.png" alt="Pay Now Button">
  <iframe scrolling="no" src="https://foo.com/dev/product/iframepage2/"></iframe>
</div>
RaJesh RiJo
  • 4,302
  • 4
  • 25
  • 46
Dan382
  • 976
  • 6
  • 22
  • 44
  • Possible duplicate of [jQuery to trigger a click on an iFrame?](https://stackoverflow.com/questions/16928860/jquery-to-trigger-a-click-on-an-iframe) – Salketer Aug 23 '17 at 09:23
  • 2
    Browsers put protections so users cannot play with pages that are not from same domain... To prevent exactly what you are trying to do! Big "Get it free" button that submits a paypal payment... That's called XSS and is disallowed! – Salketer Aug 23 '17 at 09:25
  • https://stackoverflow.com/a/27332843/4229270 – Sinto Aug 23 '17 at 09:34
  • All hosted on the same site, the iframe doesn't point externally. – Dan382 Aug 23 '17 at 12:24

1 Answers1

-1

Iframe - not button it is enother DOM structure and cant be clicked. Button in iframe can be clicked only selected first by $() And access to it may be obtained only if iframe hosted on same domain as main page - in another case it is XSS attack - the browser policy must prevent it. you can past id of element you want to click as atribute of img tag and simulate click like this:

$('#Iframe').contents().find('#button id').click();
  • Just to clarify as I see this has caused some confusion above also, the iframe is on a different page of the same site. The iframe shouldn't be seen as an XSS attack as it's hosted on the same site. – Dan382 Aug 23 '17 at 12:23