0

I tested calling parent's function in iframe. Normal function could be called through parent. But when I use the arrow function I get an "is not a function" error. What is the difference between calling common function and arrow function within iframe? Here is the code I used for testing.

<html>
    <head>
        <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    </head>

    <body>
        <iframe></iframe>

        <script>
            function a() {
                console.log("a");
            }
            const b = () => {
                console.log("b");
            };
        </script>

        <script type="text/javascript">
            let ascript =
                "<scr" + 'ipt type="text/javascript">parent.a();</scr' + "ipt>";
            $("iframe").contents().find("body").append(ascript);
            let bscript =
                "<scr" + 'ipt type="text/javascript">parent.b();</scr' + "ipt>";
            $("iframe").contents().find("body").append(bscript);
        </script>
    </body>
</html>
extradeck
  • 366
  • 1
  • 5
  • 19

0 Answers0