Cross Domain IFrame element.scrollIntoView() Safari Issue

后端 未结 2 1006
清歌不尽
清歌不尽 2021-01-03 07:56

I have ran into an issue that is plagued all over google but none of the provided solutions work correctly. I assume the majority of these solutions do not account for cross

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-03 08:44

    The other option is iframeResizer library. There are two methods you can use from within iframePage: scrollTo and scrollToOffset, which do pretty much the same what you've described - they communicate via messages. It solved this problem for us in Safari.

    Inside the parent page, when setting up resizing for the iframe, you have to assign a callback function to its onScroll event:

    iframeNode.iframeResize({ 
      ...,
      onScroll: ({x,y}) => callback
    }
    

    And inside iframe page:

    if('parentIFrame' in window){
      window.parentIFrame.scrollTo(0, someNode.offsetTop);
    }
    

提交回复
热议问题