Skip to content

Instantly share code, notes, and snippets.

@matiaslopezd
Last active February 13, 2022 02:59
Show Gist options
  • Save matiaslopezd/74d6c7fb7d42978bdfa77237a68ed24b to your computer and use it in GitHub Desktop.
Save matiaslopezd/74d6c7fb7d42978bdfa77237a68ed24b to your computer and use it in GitHub Desktop.
Get all content of website and put inside to an Iframe. [Not compatible with X-Frame-Options: DENY]
(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'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment