Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept window and document arguments in polyfill method #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

james2406
Copy link

This will allow the window and document context to be overridden, useful when targeting another document on the page (e.g. an iframe)

@iamdustan
Copy link
Owner

Would you call this with something like polyfill(document.querySelector('iframe').contentWindow?

I assume it isn’t possible to load the polyfill on the iframe itself as well 🤔

@james2406
Copy link
Author

james2406 commented May 30, 2019

Yes, that would apply the polyfill to the iframe.

In my case, I am using the react-frame-component library to render my react app in an iframe.

I'm then using the frames context to apply the polyfill to that iframe:

import Frame, { FrameContextConsumer } from 'react-frame-component'
import smoothscroll from 'smoothscroll-polyfill';

const MyComponent = (props, context) => (
  <Frame>
    <FrameContextConsumer>
      {
        // Callback is invoked with iframe's window and document instances
        ({ window, document }) => {
          smoothscroll.polyfill(window, document);
          // Render Children
        }
      }
    </FrameContextConsumer>
  </Frame>
);

Tested on chrome, safari, firefox, ie11 and iOS

@iamdustan
Copy link
Owner

This is only necessary because we don’t auto-polyfill on load, correct? If we did, then the solution would be to just load the script into the iframe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants