html - How I can mute audio from iframe? -


i'm creating tribute page (for freecodecamp.com) elon musk , wanted include game page via attribute. possible mute autoplay audio? page url: https://codepen.io/auginis/full/bdwbzw/ game: https://blastar-1984.appspot.com/ here code it:

<iframe src="https://blastar-1984.appspot.com/" width="1000px" height="1000px">   <p>sorry, browser not support game</p> </iframe> 

if can use sachin's solution, go it, i'm pretty sure works media elements, audio , video elements, last checked (spec). things change fast, maybe you're in luck.

if can't change @ iframe level, you're going run cross origin issues. if can control headers of app you're embedding, x-frame-origins friend. if use header loosen restrictions on game's original page, javascript need this:

var iframe = document.queryselector('iframe[src="https://blastar-1984.appspot.com/"]');  // code tidied up, depending on how familiar game code  iframe.contentdocument.getelementbyid("muted").checked = true;  iframe.contentwindow.speaker[0].muted = true  iframe.contentwindow.speaker[1].muted = true

if, however, you're not lucky, same origin policy might have beat. in case, i'd suggest making div , replacing iframe when click "play" (excuse lazy css in snippet): example. gives added bonus of not loading content before user wants (which performance / mobile browsers).

good luck!


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -