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

后端 未结 2 2110
伪装坚强ぢ
伪装坚强ぢ 2021-02-19 07:48

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

2条回答
  •  野性不改
    2021-02-19 07:54

    I used sandbox function in this code on my Streaming Site where i Embed 3rd Party iframe and they also have sandbox protection check but for that iv'e added removeAttribute in my JS so if you change src of the iframe from some other button you can click this button to add sandbox attribute to your iframe or you can also add the click function in your code where you get your iframe successfully.

    //JS
    window.onload = function(){
        var button = document.getElementsByName("sandbox")[0]
        var iframe = document.getElementsByName("framez")[0]
        button.addEventListener('click',sndbx,false);
    
        function sndbx(){
        var nibba = document.getElementById("framez").src;
        if(iframe.sandbox == 'allow-forms allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation'){
        document.getElementById("framez").removeAttribute("sandbox"); 
        }
        frames['framez'].location.href=nibba;
        iframe.sandbox = 'allow-forms allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation';
        }
    } 
    
    
    
    
    
    

提交回复
热议问题