Tuesday, February 13, 2018

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

Leave a Comment

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.

1 Answers

Answers 1

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.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment