html – Run a Javascript command into a iframe-ThrowExceptions

Exception or error:

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?

How to solve:

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

###

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();

Leave a Reply

Your email address will not be published. Required fields are marked *