jquery - 通过 jquery 选择器访问 iframe 中的变量

标签 jquery iframe

我有以下内容:

<iframe id="test">
   <script>
     variable='hi';
   </script>
</iframe>

我需要知道如何通过 jquery 选择器从顶部窗口访问变量,如 $("#test").variable ?

最佳答案

你可以尝试:

$("#test")[0].contentWindow.variable;

关于jquery - 通过 jquery 选择器访问 iframe 中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6649024/

相关文章:

jquery - 使用jQuery按钮单击更改iFrame的URL?

javascript - 从打开的函数中关闭花式框 'fancybox'

javascript - 下拉列表问题

javascript - 检查 iframe 内的窗口是否已关闭

javascript - AngularJS 中是否有可能捕获 "load denied by x-frame option"错误?

javascript - 可以将外部 iframe 包含到 google chrome 扩展中吗

单击按钮时的 jquery 对话框

php - Ajax不调用回调函数

javascript - 表单更改时显示固定 DIV,保存表单时隐藏它

html - 无法获取 z-index 以在菜单内容上正确堆叠视频 iframe