question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interact.js not working with elements in iframes if they was created in parent window

See original GitHub issue

Actual behavior

I have an iframe inserted into my main site and I need to create elements inside the iframe from the parent context. But interact.js doesn’t work if I create new elements from the parent context and then insert them in the iframe. In a real application I cannot create nodes from an iframe document, because the elements are created by the framework (Riot.js) and I cannot control the creation of components.

Demo: https://jsfiddle.net/kachurun/bugqc5dk/79/

Problem on this line: https://github.com/taye/interact.js/blob/55d5d57c4f1ad2f728109bb839f1ed99a45d8ba1/packages/%40interactjs/utils/is.ts#L29

Because thing really not instance of _window.Element, but instance of win.window.Element. I’m not sure if I know the correct way to fix this, except to add a check to the parent window, or remove the DOM2 part of the condition.

System configuration

interact.js version: 1.10.3

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tayecommented, Feb 16, 2021

interact('.target', { context: iframe.contentDocument })

Docs need updating 🙂

0reactions
codextechcommented, Dec 23, 2022

@taye thank you for answer interact('.target', { context: iframe.contentDocument })

This worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interact.js not working with elements in iframes if they was created in ...
I have an iframe inserted into my main site and I need to create elements inside the iframe from the parent context. But...
Read more >
Interact.js - move iframe with a handle - Stack Overflow
So, I've made onMove as global by adding it to window. So, when onMove is called I'll translate the entire iframe from the...
Read more >
Clone target draggable - interact.js
To make an element be the handle of a parent draggable, use the allowFrom setting option to allow an action to start only...
Read more >
Cross-window communication - The Modern JavaScript Tutorial
When an iframe comes from the same origin, and we may access its document , there's a pitfall. It's not related to cross-origin...
Read more >
Best practices for React iframes - LogRocket Blog
When a resource is rendered in an iframe, it functions independently of the parent component where it is embedded. Therefore, neither the parent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found