是否从iframe外部触发全屏显示?

时间:2018-08-14 07:26:02

标签: javascript jquery

我正在使用Cloud Games添加iframe,并且它们在iframe画布中具有全屏选项以将其切换为全屏。 当我们按下“全屏”按钮时,有没有办法让我全屏显示?

HTML

<div>
  <button id="trigger">Full Screen</button>
</div>
<section>
  <iframe src="https://cloudgames.com/games/html5/soldiers-combat-new-en-s-iga-cloud/index.html?pub=10" name="cloudgames-com" width="913" height="516" frameborder="0" scrolling="no" allowfullscreen="allowfullscreen" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" webkitallowfullscreen="webkitallowfullscreen"></iframe>
</section>

JS

$('#trigger').click(function(e) {
  e.preventDefault();
  console.log('Button Pressed');
});

链接到Codepen

Full Screen Button

1 个答案:

答案 0 :(得分:0)

我发现了这个:https://codepen.io/ssk7833/pen/mVOXXp

我认为这部分与您有关:

var iframe = document.querySelector('#container iframe');
    // Do fullscreen
    if (iframe.requestFullscreen) {
      iframe.requestFullscreen();
    } else if (iframe.webkitRequestFullscreen) {
      iframe.webkitRequestFullscreen();
    } else if (iframe.mozRequestFullScreen) {
      iframe.mozRequestFullScreen();
    } else if (iframe.msRequestFullscreen) {
      iframe.msRequestFullscreen();
    }