调用iframe 中的js[兼容各种浏览器]
2014-09-11 18:31
471 查看
*chrome浏览器需要在服务器环境中测试
iframe html:
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> </head> <body> <div id="d1"></div> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"> </script> <script> $(function() { var iframe = '<iframe id="f1" src="frame.html"></iframe>'; $("#d1").html(iframe); onIframeLoaded(f1,function() { executeIframeFun("a"); }); /** * iframe加载成功事件 **/ function onIframeLoaded(iframe,onload) { if (iframe.attachEvent) { iframe.attachEvent("onload", function() { onload(); }); } else { iframe.onload = function() { onload(); }; } } /** * 执行iframe的方法 * funName 方法名 */ function executeIframeFun(funName) { if (window.frames['f1'].contentWindow) { window.frames['f1'].contentWindow[funName](); } else { window.frames['f1'][funName](); } } }); </script> </body> </html>
iframe html:
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> </head> <body> 子页面 <script type="text/javascript"> function a(){ alert('子页面'); } </script> </body> </html>
相关文章推荐
- js操作iframe兼容各种浏览器
- js操作iframe兼容各种主流浏览器示例代码
- 兼容各种浏览器下调用iframe里面的函数
- js操作iframe兼容各种主流浏览器示例代码
- [置顶] js操作iframe兼容各种浏览器
- jquery兼容各种浏览器的iframe自适应高度的脚本
- 基于jquery的兼容各种浏览器的iframe自适应高度的脚本
- 兼容主流浏览器的iframe自适应高度js脚本
- js 获取屏幕各种宽高的方法(浏览器兼容)
- js 实现文字无缝滚动(图片无缝滚动) 兼容各种浏览器
- 万能js实现翻页,动态生成内容自动翻页,兼容各种浏览器(已测试)----神器版!
- js,jquery字符串转换json,兼容各种浏览器
- jquery 调用iframe页面中js的方法 兼容Ie,FF,chore浏览器
- 基于asp.net + easyui框架,js实现上传图片之前判断图片格式,同时实现预览,兼容各种浏览器+下载
- 【开发过程问题汇总系列】【JS控制 iframe跳转】兼容 FireFox和IE内核的浏览器
- 兼容各种浏览器的‘设为首页’和‘加入收藏’的js代码
- JS兼容各种浏览器的回车事件监控
- 在父窗口调用iframe里面的函数(各浏览器兼容)
- 纯js实现Div在页面垂直居中!可根据浏览器大小的改变而改变!兼容各种浏览器----神器版!
- (造福中国前端界)纯前端Js完美解决各种汉字urlencode,urldecode,编码解码问题,不借助任何字库,内码表,轻松一行,兼容IE8+,chrome,firefox,safari等主流浏览器