Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to block pop-up, banner ads and video ads in iframe?

I'm embedding video that has an exit pop-up banner ads and video ads. When you anywhere in video then popups open automatic or how to click on X icon to close banner ad.

.iframe{
  width: 100%;
  float: left;
  margin-top: 5px;
}
<div class="iframe">
   <iframe width="1000" height="600" src="https://www.youtube.com/embed/Sb_60g3u1LU" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>
</div>

I am using other third party websites to host videos like vidzi.tv & openload.co and these sites are full with pop ups and banner ads in video player.

like image 773
Dom Avatar asked Feb 02 '18 18:02

Dom


People also ask

How do I stop iframe popups?

If you want to block an iframe from opening windows, you can use the new HTML5 "sandbox" attribute on your iframe.

Does AdBlock prevent popup?

AdBlock blocks pop-ups by default. Once you've installed it, you should stop seeing annoying pop-ups in Chrome, Firefox, Edge, Safari, Android or iPhone. If you're still seeing pop-ups, it could be a sign that your computer has been infected with a form of malware called "adware".


1 Answers

You can add sandbox attribute in your iframe. Only the values you add to the attribute will be allowed. Any value you do not add in the sandbox attribute will not be allowed by browser.

Sandbox attribute has following values:

allow-forms
allow-pointer-lock
allow-popups
allow-same-origin
allow-scripts
allow-top-navigation

I have modified your code to include sandbox option, but have NOT added allow-popups, so popups will not be allowed in this iframe.

<div class="iframe">
   <iframe sandbox = "allow-forms allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation" width="1000" height="600" src="https://www.youtube.com/embed/Sb_60g3u1LU" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>
</div>

You can find more about sandbox attribute here. Please note that this attribute is new in HTML5.

like image 151
DarthWader Avatar answered Sep 18 '22 02:09

DarthWader