是否可以从父窗口访问沙盒内容?内容来自同一个域。我知道沙盒内容无法访问托管窗口,但托管窗口不应该能够访问沙盒内容吗?
<iframe id="myframe" sandbox="allow-scripts allow-forms" srcdoc='<html><head></head><body>
<form id="myform"><span>First Name</span><input name="firstname" width="100px" /></form>
</body></html>'>
</iframe>
<br/>
<button id="btn" type="button">Submit</button>
在父窗口中运行的脚本
$(function(){
$("#btn").click(function(){
//approach 1
let form1 = $("#myform");
console.log(form1.length)
console.log(form1.serialize());
//approach 2
let form2 = $("#myframe").contents().find('form');
console.log(form2.length)
console.log(form2.serialize());
})
})
这两种方法都不起作用 JS 小提琴