Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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 iframe-won';除非重新打开,否则无法滚动_Javascript_Iframe_Scroll_Ios8_Mobile Safari - Fatal编程技术网

Javascript iframe-won';除非重新打开,否则无法滚动

Javascript iframe-won';除非重新打开,否则无法滚动,javascript,iframe,scroll,ios8,mobile-safari,Javascript,Iframe,Scroll,Ios8,Mobile Safari,目前我正在开发一个小部件,它位于我页面上的iframe中。我可以选择让访问者通过iframe内的联系人表单向我发送消息(iframe比iframe长,因此需要滚动),但是,在iOS8上使用Chrome时,除非我关闭并重新打开小部件,否则消息表单不会滚动。有没有其他人遇到过这种情况,或者知道是什么原因造成的 指示iframe滚动的代码如下所示: frameDoc.body.firstChild.setAttribute( 'style', ['width: 100%', 'h

目前我正在开发一个小部件,它位于我页面上的iframe中。我可以选择让访问者通过iframe内的联系人表单向我发送消息(iframe比iframe长,因此需要滚动),但是,在iOS8上使用Chrome时,除非我关闭并重新打开小部件,否则消息表单不会滚动。有没有其他人遇到过这种情况,或者知道是什么原因造成的

指示iframe滚动的代码如下所示:

frameDoc.body.firstChild.setAttribute(
   'style',
    ['width: 100%',
    'height: 100%',
    'overflow-x: hidden',
    'overflow-y: auto !important',
    '-webkit-overflow-scrolling: touch !important'].join(';')
if (
  existingStyle.indexOf('-webkit-overflow-scrolling') === -1) {
   frameFirstChild.setAttribute('style',
    `${existingStyle};-webkit-overflow-scrolling: touch;`);
  }
); 好的,新问题。当我打开iframe时,会添加“-webkit overflow scrolling:touch”样式,但当我关闭它并重新打开时,该样式会消失。如果将其关闭并再次打开,则会再次添加样式。我的代码如下:

frameDoc.body.firstChild.setAttribute(
   'style',
    ['width: 100%',
    'height: 100%',
    'overflow-x: hidden',
    'overflow-y: auto !important',
    '-webkit-overflow-scrolling: touch !important'].join(';')
if (
  existingStyle.indexOf('-webkit-overflow-scrolling') === -1) {
   frameFirstChild.setAttribute('style',
    `${existingStyle};-webkit-overflow-scrolling: touch;`);
  }
此语句周围有一个setTimeout函数,但是更改超时对是否添加样式没有影响。此外,我的风险值定义如下:

var frameFirstChild = this.getDOMNode().contentDocument.body.firstChild,
    existingStyle = frameFirstChild.getAttribute('style');

解决了。不得不搬家
existingStyle=frameFirstChild.getAttribute('style')在if语句之前添加到内部,但仍然包装在setTimeout()中。

您使用iFrame有什么具体原因吗?您是否尝试在iFrame加载内容后添加样式?@skobaljic您真是个天才!浏览器加载太快,无法应用
-webkit溢出滚动:touch
,所以我设置了500毫秒的延迟,之后应用了样式,现在它工作得很好。非常感谢。