iFrame allowFullScreen 属性在 Android WebView 上不起作用

Posted

技术标签:

【中文标题】iFrame allowFullScreen 属性在 Android WebView 上不起作用【英文标题】:iFrame allowFullScreen attribute doesn't work on Android WebView 【发布时间】:2017-10-29 03:50:31 【问题描述】:

我需要在我的 android 项目中显示来自 YouTube 的视频列表,当我点击一个视频时,它应该以全屏模式启动。我按照其他主题中的建议使用来自 html 的 iFrame 的 WebView,但“allowFullScreen”属性不起作用。

我尝试了allowFullScreen、allowFullScreen = "true"、allowFullScreen = allowFullScreen 方式。

String frameVideo = "<html><body><iframe width=\"300\" height=\"300\" src=\"https://www.youtube.com/embed/47yJ2XCRLZs\" scrolling=\"no\" frameborder=\"0\" allowFullScreen=\"allowFullScreen\" webkitallowfullscreen=\"true\" mozallowfullscreen=\"true\"></iframe></body></html>";

    for(int i=0; i<number_of_videos; i++)
        video = new WebView(this);
        video.getSettings().setjavascriptEnabled(true);
        video.getSettings().setPluginState(WebSettings.PluginState.ON);
        video.loadData(frameVideo, "text/html", "utf-8");
        video.setWebChromeClient(new WebChromeClient());
        video.setId(i);
        video.setPadding(0, 0, 0, 0);
        video.setLayoutParams(new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, 900));
        root.addView(video);
    

我会避免使用 YouTube API。有什么建议吗?

【问题讨论】:

【参考方案1】:

而不是 allowFullScreen="allowFullScreen" 只需使用

<iframe 
 
 
src="https://www.youtube.com/embed/47yJ2XCRLZs" 
scrolling="no" 
allowFullScreen > 

allowFullScreen 没有任何值

【讨论】:

以上是关于iFrame allowFullScreen 属性在 Android WebView 上不起作用的主要内容,如果未能解决你的问题,请参考以下文章

更新 Youtube iframe

iframe中的页面requestFullScreen不能全屏问题

如何使用React + Typescript嵌入YouTube iframe?

表格

如何解决“允许属性将优先于allowfullscreen”警告?

JS实现图片滚动效果