0

Before i explain the problem please understand that i am not trying to access a DOM element but rather some js code from inside the iframe.

Consider my structure

<body>
    <script>
      class PlayerClient{
          constructor(){
              alert('Successfuly called')
          }
      }
    </script>

 <section id="The-Big-Picture">
    <iframe src="/app/explore/sp/home" frameborder="0" width="100%" height="91%">
        Sorry your browser does not support inline frames.
    </iframe>
 </section>
</body>

This iframe is SAMEORIGIN and all i'm trying todo is to instantiate the class PlayerClient from inside the iframe like so new window.parent.PlayerClient(). Why would i want to do this? Because i found it to be DRYer declaring the class in one location only.

Here is an image of the HTML structureenter image description here

The blue highlight returns undefined

2 Answers 2

1

Because you can't access window.PlayerClient even in the parent window. In this aspect, class is just like let or const, unlike var. You can get the explanation as Global constants do not become properties of the window object, unlike var variables. go https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const

Sign up to request clarification or add additional context in comments.

Comments

0

Could that be because scripts haven't been loaded yet in the parent window?

1 Comment

I guess it's not the case if your script is inline though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.