0

I have a Google Slides presentation embedded on my website in an iframe. I want to create a separate button (large and visible), that starts it.

I tried running $(".goog-flat-button[title='Play']").click(); in the Chrome console - no effect. Am I targeting a wrong element, or should this not work in an iframe (why not?), or am I doing something inherently wrong?

enter image description here

  • please can you put a working code base so that someone can help you – A.RAZIK Jul 15 '20 at 10:30
  • 1
    I guess your website and the slide's domain are different. Then you won't be able to, due to security aspects (cross site scripting) – casenonsensitive Jul 15 '20 at 10:41
  • @casenonsensitive Than makes sense, thank you. However, at some point, it should be all just HTML in the user's browser, that could be manipulated with JS - or is it not? – Dmitry Linov Jul 15 '20 at 11:09
  • Imagine you have a frame with a payment provider and you can just manipulate the content. The user thinks they are signing a transaction for 1$ and you just change it to 2$ – casenonsensitive Jul 15 '20 at 11:11
  • @casenonsensitive That makes sense, too, but not the case here. See the solution below. – Dmitry Linov Jul 16 '20 at 11:59

1 Answers1

1

Solution

If you inspect closely the play button doesn't listen for click events directly:

enter image description here

It does listen to different mouse events. Using this snippet you can successfully simulate the mouse behavior when clicking on the button and finally triggering the wanted behavior.

var targetNode = document.querySelector (".goog-flat-button[title='Play']");
if (targetNode) {
    //--- Simulate a natural mouse-click sequence.
    triggerMouseEvent (targetNode, "mouseover");
    triggerMouseEvent (targetNode, "mousedown");
    triggerMouseEvent (targetNode, "mouseup");
    triggerMouseEvent (targetNode, "click");
}
else
    console.error ("*** Target node not found!");

function triggerMouseEvent (node, eventType) {
    var clickEvent = document.createEvent ('MouseEvents');
    clickEvent.initEvent (eventType, true, true);
    node.dispatchEvent (clickEvent);
}
Alessandro
  • 2,848
  • 1
  • 8
  • 16