matiaslopezd
6/6/2019 - 9:58 AM

Remove all content and replace with iframe

Remove all content and replace with iframe

(function(elements) {

  function removeElements(elements){
    elements.forEach((type) => {
      const large = document.querySelectorAll(type).length;
      for (let i = 0; i < large; i++) {
        document.querySelector(type).remove();
      }
    });
  }

  function removeChilds(){
    const large = document.querySelector('body').childNodes.length
    for (i = 0; i < large; i++) {
      document.querySelector('body').childNodes[0].remove();
    }
  }

  function createIframe(){
    const style = 'width: 100%; height: 100%; overflow: hidden; margin: 0;';
    document.querySelector('html').setAttribute('style', style);
    document.querySelector('body').setAttribute('style', style);
    const iframe = document.createElement('iframe');
    iframe.src = window.location.href;
    iframe.setAttribute('style', 'width: 100%; height: 100%; border: none;');
    document.querySelector('body').appendChild(iframe);
  }

  removeElements(elements);
  removeChilds();
  createIframe();

})(['script', 'link', 'style']);

(function(elements){function removeElements(elements){elements.forEach((type)=>{const large=document.querySelectorAll(type).length;for(let i=0;i<large;i++){document.querySelector(type).remove()}})}
function removeChilds(){const large=document.querySelector('body').childNodes.length
for(i=0;i<large;i++){document.querySelector('body').childNodes[0].remove()}}
function createIframe(){const style='width: 100%; height: 100%; overflow: hidden; margin: 0;';document.querySelector('html').setAttribute('style',style);document.querySelector('body').setAttribute('style',style);const iframe=document.createElement('iframe');iframe.src=window.location.href;iframe.setAttribute('style','width: 100%; height: 100%; border: none;');document.querySelector('body').appendChild(iframe)}
removeElements(elements);removeChilds();createIframe()})(['script','link','style'])