x-frame-bypass icon indicating copy to clipboard operation
x-frame-bypass copied to clipboard

How can this be used in iframe elements injected by JS

Open chaoming opened this issue 6 years ago • 3 comments

I am trying to use document.createElement('iframe') and setAttribute('is','x-frame-bypass') to create a dynamic iframe. But not sure how to make it work on the dynamic injected iframes.

chaoming avatar Feb 07 '19 03:02 chaoming

The simplest way is: document.write('<iframe is="x-frame-bypass" src="..."></iframe>') or element.innerHTML = '<iframe is="x-frame-bypass" src="..."></iframe>'

niutech avatar Feb 08 '19 00:02 niutech

const ifrm = document.createElement('iframe'); ifrm.setAttribute('is', 'x-frame-bypass'); ifrm.setAttribute('width', '500px'); ifrm.setAttribute('height', '350px'); ifrm.setAttribute('src', 'your HTML URL');

ChenReuven avatar Mar 25 '20 10:03 ChenReuven

Add function to onload. Assuming you've already reference Jquery.

<iframe is="x-frame-bypass" id="iframe" onload="oniFrameLoad(this)" src="https://..." width="100%" height="100%" frameBorder="0"></iframe>

<script>
function oniFrameLoad() {
	var scriptTag = "....";
	scriptTag += "}";

	console.log(scriptTag);
	//inject content into iframe
	$('#iframe').contents().find('body').append($('<script>').html(scriptTag))
};
</script>

ShaneOss avatar Jun 17 '20 12:06 ShaneOss