-2

I have a page that contains multiple iframes relating to external sites.

How can I mute my entire page using javascript or jquery ?

Arkadiusz G.
  • 1,024
  • 10
  • 24
  • 2
    Possible duplicate of [How to mute all sound in a page with JS?](http://stackoverflow.com/questions/14044761/how-to-mute-all-sound-in-a-page-with-js) – Obsidian Age Mar 19 '17 at 19:35
  • frames? as in iframes? You can't touch those! – Miro Mar 19 '17 at 19:40
  • 1
    @ObsidianAge It's not a duplicate, as this question is about accessing frames with external content. – Schlaus Mar 19 '17 at 19:40
  • Possible duplicate of [jQuery/JavaScript: accessing contents of an iframe](http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe) –  Mar 20 '17 at 18:49

2 Answers2

0

You can't. You would need to access the contents of the frames, but if you're loading external sites, then you'll run into same origin policy.

For some more answers on the subject check this question.

Community
  • 1
  • 1
Schlaus
  • 18,144
  • 10
  • 36
  • 64
0

If the sites you're loading are fairly simple, you can 'load' them trough php and add a <base> tag to the html.

Note: It won't work on complex websites with lot's of external resources

Create a file iframe-loader.php: with this content:

<?php
error_reporting(0);

$url = $_REQUEST['url'];
$html = file_get_contents($url);

$dom = new domDocument;
$dom->strictErrorChecking = false;
$dom->recover = true;
$dom->loadHTML($html);

//BASE
$head = $dom->getElementsByTagName('head')->item(0);
$base = $dom->createElement('base');
$base->setAttribute('href',$url);

if ($head->hasChildNodes()) {
    $head->insertBefore($base,$head->firstChild);
} else {
    $head->appendChild($base);
}



header('Content-Type: text/html; charset=utf-8');
echo $dom->saveHTML();

?>

Then you can use the loader by feeding it a url:

<iframe src="iframe-loader.php?url=http://www.example.com" />

You'll have access to the iframes as they are not conflating against the same origin policy.

Now you can use the answer that @ObsidianAge mentioned in the comments.

Miro
  • 8,402
  • 3
  • 34
  • 72