I have a page that contains multiple iframes relating to external sites.
How can I mute my entire page using javascript or jquery ?
I have a page that contains multiple iframes relating to external sites.
How can I mute my entire page using javascript or jquery ?
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.
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.