Toggle iFrame Text Panel

I am trying to find out if it is possible to programmatically change the sandbox value for an iFrame.

From MDN iframe :

When an embedded document has the same origin as the main page, it is strongly discouraged to use both allow-script and allow-same-origin scripts at the same time, as this allows the embedded document to programmatically remove the sandbox attribute. Although this is accepted, this case is no safer than using the sandbox attribute.

However, changing the attribute in the parent object does not successfully launch the sandbox, as that would imply in it.

document.getElementById('myFrame').setAttribute('sandbox', 'allow-scripts');

A page loaded into this iFrame can successfully access the parent object, which would not have happened if the sandbox worked. The attribute modifies, but the protection is erroneous because it does not prevent access to the patent.

console.log(window.parent.document);

The above still works in iFrame, which includes the software programmatically. This applies to both Chrome and Firefox, which implies either undocumented functionality or a poorly implemented specification.

Anyone have any ideas on what would be a suitable expectation?

+4
source share
2 answers

: http://jsfiddle.net/yAwxy/ , script onLoad b/c iframe . onDomready, b/c, script . , :

<iframe id="myFrame" srcdoc="<script>console.log('Executing script inside iFrame')</script>">
</iframe>

script

console.log('Executing script inside page')

script console.log('Executing script inside page') onLoad, outpu :

Executing script inside iFrame 
Executing script inside page 

onDomready:

Executing script inside page 
Executing script inside iFrame 

. http://jsfiddle.net/yAwxy/1/.

, OndomReady

0

iframe Internet Explorer iframe. , , javascript sandbox , iframe , , iframe ( javascript: URI src=), iframe, , , .

Internet Explorer, , , FireFox Chrome, sandbox. Chrome FireFox src= javascript: function(), ​​ = "allow-scripts". , IE sandbox src= javascript: function() iframe.

, sandbox , iframe , srcdoc, sandbox IE srcdoc.

, , iframe , sandbox iframe iframe.

0

Source: https://habr.com/ru/post/1525976/


All Articles