停止来自父级的iframe中的所有音频 [英] Stop all audio inside iframes from parent

查看:72
本文介绍了停止来自父级的iframe中的所有音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个index.html,其中包含多个iframe.启动index.html时,我正在将不同的html页面加载到每个iframe中.每个html页面中都有多个音频标签.我使用index.html在iframe之间导航.

I have one index.html that has several iframes in it. I am loading a different html page into each iframe when the index.html is launched. Each html page has multiple audio tags inside them. I use the index.html to navigate between iframes.

索引中是否有可以停止所有音频的功能?当我想在当前iframe播放完音频之前跳到"另一iframe时,音频彼此之间会出现问题.我知道如何从iframe访问父索引文件,但是如何才能从索引中定位所有iframe并停止音频标签?我进行了无休止的搜索,但没有找到解决方法.

Is it possible to have a function in the index that will stop all audio? I'm having issues with audio stepping on top of each other when i'm want to 'jump' to another iframe before the current one has finished playing audio. I know how to access the parent index file from the iframe, but how can I target all iframes from the index and stop the audio tags? I've searched endlessly but haven't found a solution.

这是我试图开始使用的功能,但它似乎只能捕获索引中的音频标签,而不是iframe中的音频标签.

Here is the function that I was trying to get to work, but it only seems to catch the audio tag in the index, not the ones inside the iframes.

function audioClear(){
    var sounds = window.document.getElementsByTagName('audio');
    for(i=0; i<sounds.length; i++) sounds[i].pause();
};

任何指导将不胜感激.我在使用音频方面还很陌生,所以我会尽力而为.

Any guidance would be greatly appreciated. I'm still fairly new to working with audio so I'm doing my best.

推荐答案

应该执行类似的操作.
它应该迭代所有帧以找到音频.
试试吧.

Something like this should do.
It should iterates all frames to find the audios.
Try it.

var frames = window.frames;
for (var i = 0; i < frames.length; i++) { 
  var sounds = frames[i].document.getElementsByTagName('audio');
  for(j=0; j<sounds.length; j++){
    sounds[j].pause();
  }
}

这篇关于停止来自父级的iframe中的所有音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆