Skip to content

Controlling canvas size in embedded iframe #1706

Open

Description

@catarak

"I want to include some sketches in a blog-like article via the embed feature, so I am dealing with iframes. I am having trouble to automatically get the height of my sketch, as this is of course a cross-origin scenario, so I cannot read the canvas' height via JS.

"Is this something that could/would be solved by the API? As in: I would be able to access the sketch height via the API? Or are there even any other solutions for that, that I am missing?"

Originally posted by @trych in #1075 (comment)

Activity

  1. catarak commented on Dec 14, 2020

    @catarak
    MemberAuthor

    One thing that comes to mind is that you could, in the embedded sketch, set the canvas size to windowWidth and windowHeight, and then set the width and height of the iframes to how big you want the sketches to be.

    If you wanted to access the canvas from outside of the iframe, you'd have to use the web messaging api (i.e. window.postMessage and window.on("message")) and then have a handler within your sketch. This way is way more complicated and I think the first way I suggested is much simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature RequestProposal for adding a new functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions