Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 模拟iPhone时,React iframe组件在Chrome中加载时滚动窗口_Javascript_Iphone_Reactjs_Iframe_Google Chrome Devtools - Fatal编程技术网

Javascript 模拟iPhone时,React iframe组件在Chrome中加载时滚动窗口

Javascript 模拟iPhone时,React iframe组件在Chrome中加载时滚动窗口,javascript,iphone,reactjs,iframe,google-chrome-devtools,Javascript,Iphone,Reactjs,Iframe,Google Chrome Devtools,我有一个简单的IFrame组件,我只需要向它传递src、height和onLoad。父对象只是在iframe下面有一些文本。当iframe加载时,父对象滚动显示页面底部。只有当模拟设备是iPhone(所有版本)时,Chrome才会出现这种情况;它在模拟的Android设备上工作。因为我没有iPhone,所以没有在实际设备上进行测试 这是IFrame组件: export class IFrame extends Component { static propTypes = { src:

我有一个简单的IFrame组件,我只需要向它传递src、height和onLoad。父对象只是在iframe下面有一些文本。当iframe加载时,父对象滚动显示页面底部。只有当模拟设备是iPhone(所有版本)时,Chrome才会出现这种情况;它在模拟的Android设备上工作。因为我没有iPhone,所以没有在实际设备上进行测试

这是IFrame组件:

export class IFrame extends Component {
  static propTypes = {
    src: PropTypes.string.isRequired,
    onLoad: PropTypes.func,
  };

  constructor(props) {
    super(props);
    this.iframe = React.createRef();
  }

  handleOnLoad = () => {
    const { onLoad } = this.props;

    window.scrollTo(0, 0);

    if (onLoad) {
      onLoad();
    }
  }

  render() {
    return (<iframe
      ref={this.iframe}
      src={this.props.src}
      onLoad={this.handleOnLoad}
    />);
  }
}
导出类IFrame扩展组件{
静态类型={
src:PropTypes.string.isRequired,
onLoad:PropTypes.func,
};
建造师(道具){
超级(道具);
this.iframe=React.createRef();
}
handleOnLoad=()=>{
const{onLoad}=this.props;
滚动到(0,0);
if(onLoad){
onLoad();
}
}
render(){
返回();
}
}
这就是它的使用方式

class MyComponent extends Component {
  static propTypes = {
    iframeSrc: PropTypes.string.isRequired,
  };

  handleIframeLoad() {
    // Do something. Or nothing.
  }

  render() {
    return (
      <Fragment>
        <IFrame
          src={this.props.iframeSrc}
          onLoad={this.handleIframeLoad}
        />
        <SomeOtherComponentThatOnlyRendersText />
      </Fragment>
    );
  }
}
类MyComponent扩展组件{
静态类型={
iframeSrc:PropTypes.string.isRequired,
};
handleIframeLoad(){
//做点什么,或者什么都不做。
}
render(){
返回(
);
}
}
我试着把
窗口滚动到(0,0)当iframe加载但不工作时。它被调用,但当您登录
窗口。滚动
,它是
0
。iframe加载了它的内容,但它实际上还是做了一些其他的事情,我想?iframe的来源不是我的,所以我无法控制它。我还尝试在滚动之前设置一个
setTimeout
,然后调用
scrollTo
,当然这似乎不是一个好的解决方案

如有任何关于此问题的见解,将不胜感激:)

更新:

我尝试加载一个可以嵌入iframe()中的公共站点,但它不会滚动父站点。所以它可能是第三方来源。但问题仍然是,为什么只有在使用Chrome时才会出现在模拟的iPhone上


滚动父对象的源具有一个引导模式,该模式会弹出并显示微调器/进度,然后显示文档的内容。可能是模式导致了滚动,因为它滚动的父对象刚好足以使模式的顶部接触页面/父对象的顶部。

您能提供一个易于复制的示例来使用它吗?我不确定,但这可能有关联:PS:检查注释too@ffeast就这样,,我尝试用自动弹出的引导模式查找其他资源,但它们没有那种背景页面滚动的怪癖。