TypeError: window.parent.updatepic 不是函数,当我尝试从 iframe 访问函数到他的
TypeError: window.parent.updatepic is not a function when i try to access function from iframe to his window's parent
我的页面中有一个iframe,在这个iframe中,我正在加载一个包含此Javascript代码的页面:
<script>
var ready;
ready = function() {
window.parent.updatepic("#{@user.photo_url.to_s}")
};
$(document).ready(ready);
$(document).on('page:load', ready);
</script>
包含我的 iframe 的页面有一个脚本如下:
var ready;
ready = function() {
function updatepic(pic){
$("#image").attr("src", pic);
}
};
$(document).ready(ready);
$(document).on('page:load', ready);
正如您在上面的第一个代码示例中看到的:
window.parent.updatepic("#{@user.photo_url.to_s}")
我尝试从 iframe 内部调用 updatepic
函数,但在控制台中出现错误:
TypeError: window.parent.updatepic is not a function
我找不到或理解我在这里做错了什么?请帮忙。
父
窗口中的updatepic
方法包装在闭包(您分配给ready
变量的函数)中。因此,该函数在全局window
命名空间中不可用。
将updatepic
的定义移到分配给ready
的函数之外。
相关文章:
- 允许父窗口在其不同域的子iframe上调用函数
- iFrame url更改时执行函数
- 使用jQuery来foreach iframe-src,并通过函数获取ID和操作
- 访问iframe函数
- i'm无法从iframe中调用父函数
- 在iframe中禁用onload函数的Javascript
- 如何将javascript文件插入到iframe中,然后调用插入的javascript中的函数
- 从iframe调用Parent函数,然后更新iframe表单值
- 如何在我的页面中调用Iframe JavaScript函数
- 如何等到iframe刷新完成后再执行函数
- 这个基于iFrame选择器的if函数有什么问题
- 将自定义javascript函数应用于iframe元素
- iframe内容加载后触发js函数
- 从父窗口调用iframe函数
- document.ready函数在iframe内不起作用
- 节点webkit iframe访问父nw函数
- 当用户滚动到 iframe 或 iframe 位于视口中时,从 iframe 调用 js 函数
- 从 iframe 内部到父级的触发函数
- 调用在 IE8 中从 iFrame 写入父级的父函数
- 如何javascript调用iframe加载的文件函数