您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

从父页面在iframe中调用JavaScript代码

从父页面在iframe中调用JavaScript代码

假设您的iFrame的ID为“ targetFrame”,而您要调用函数targetFunction()

document.getElementById('targetFrame').contentWindow.targetFunction();

您也可以使用window.frames代替访问框架document.getElementById

// this option does not work in most of latest versions of chrome and Firefox
window.frames[0].frameElement.contentWindow.targetFunction();
javascript 2022/1/1 18:19:21 有469人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶