2

I want to block pop-ups coming from iframe. I'm using php codeigniter where i'm taking iframes from db,
Note: Iframes are dynamic we are just displaying it
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 ?

Habib Rehman
  • 590
  • 3
  • 15
  • 36

1 Answers1

2

UPDATE

Actually this isn't really concating string I think, but it works here and it's dynamic.

enter image description here

SNIPPET 2

var ifrm1 = $('<iframe id="ifrm1" name="ifrm1" src="about:blank" sandbox="allow-popups"></iframe>');

$('body').append(ifrm1);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

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'

SNIPPET 1

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>
Community
  • 1
  • 1
zer00ne
  • 41,936
  • 6
  • 41
  • 68