2

i have a HTML page that include in a iframe another page, like this:

<!DOCTYPE html>
<html>
<head>
    <style>
        iframe{width:100vw;height:100vh;border:0}
    </style>
    <script>
        function reload(){setTimeout(function(){document.body.firstElementChild.src+="",reload()},300000)}reload();
    </script>
</head>
<body>
<iframe id="mappa" src="*********"></iframe>
</body>
</html>

Now i want to run a command into in this iframe, like this: $(".SimpleSliderDecrementButton").trigger("click");

How can i made this command running into the iframe?

  • 3
    Does this answer your question? [Invoking JavaScript code in an iframe from the parent page](https://stackoverflow.com/questions/251420/invoking-javascript-code-in-an-iframe-from-the-parent-page) – evolutionxbox Feb 23 '20 at 13:09

2 Answers2

0

You can try to use emit. $(youriframe).emit('click'), or dispatchEvent('click'). Also you can check the specs about emiting events.

0

https://codesandbox.io/s/ancient-shadow-9b4yk

You can use iframe.contentDocument to get access to .SimpleSliderDecrementButton inside iframe and .click() instead of .trigger().

const iframe = document.querySelector("iframe");
$(iframe.contentDocument).find(".SimpleSliderDecrementButton").click();
artanik
  • 2,599
  • 15
  • 24