Habib Rehman Habib Rehman - 5 months ago 30
CSS Question

Can we Invoke sandbox through css/jquery in iframe

I want to block pop-ups coming from iframe. I'm using php codeigniter where i'm taking iframes from db, and thing i want to do is invoke sandbox in iframe tag,

<iframe src="demo_iframe_sandbox.htm" sandbox></iframe>


as user haven't done it in iframe is there a way that it could be done through css/jquery ?

Answer

It works because it was blocked :P If you want to block popups the last thing you want to do is use a sandboxed iframe. But if you want to set the sandbox attribute programmatically, you can use this by assigning the value by the array allow[]s index. Ex. allow[2] = 'allow-popups'

var ifrm = document.querySelector('iframe');

var allow = ['allow-forms', 'allow-pointer-lock', 'allow-popups', 'allow-same-origin', 'allow-scripts', 'allow-top-navigation'];

ifrm.setAttribute('sandbox', allow[2]);
<iframe src="demo_iframe_sandbox.htm" sandbox></iframe>

Comments