Created
June 29, 2019 12:52
-
-
Save FerraBraiZ/1f633909833d01d800b4e3441d987494 to your computer and use it in GitHub Desktop.
friendly iframe javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/* Originally taken from: https://www.tikalk.com/posts/2017/11/23/your-filename/ */ | |
(function(){ | |
let iframe, domain, doc, where,url; | |
try { | |
url = '//locahost:8080/public/friendly-iframe.js'; | |
iframe = document.createElement('iframe'); | |
iframe.src = 'javascript:false'; | |
iframe.title = ''; | |
iframe.role='presentation'; | |
iframe.frameBorder = '0'; | |
iframe.tabIndex = '-1'; | |
(iframe.frameElement || iframe).style.cssText = 'position:absolute;width:0;height:0;border:0;'; | |
where = document.getElementsByTagName('script')[0]; | |
where.parentNode.insertBefore(iframe, where); | |
doc = iframe.contentWindow.document; | |
} catch(e) { | |
domain = document.domain; | |
iframe.src='javascript:let d=document.open();d.domain="' + domain + '";void(0);'; | |
iframe.src = 'javascript:void((function () {' | |
+ 'document.open("text/html", "replace");' | |
+ 'document.domain = "' + domain + '";' | |
+ 'document.close();' | |
+ '})())'; | |
doc = iframe.contentWindow.document; | |
} | |
doc.open('text/html', 'replace').FIF = function() { | |
if (domain) this.domain = domain; | |
let scr = this.createElement('script'); | |
scr.src = url; | |
this.body.appendChild(scr); | |
}; | |
doc.write('<body onload="document.FIF();">'); | |
doc.close(); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment