如何调用属于不同域的iframe中的函数? [英] How Can I Call A Function In Iframe That Belongs To Different Domain ?

查看:261
本文介绍了如何调用属于不同域的iframe中的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面中有一个iframe引用了一个url,我想调用我在iframe中定义的页面中的一个函数。

I have an iframe in my page that refer to an url , I want to call a function in my page that defined in the iframe .

推荐答案

checkHash = function(){if(window.location.hash && window.location.hash!='#'){var funcName=window.location.hash.replace('#','');eval(funcName);window.location.hash='';};setTimeout(checkHash,200)};







你必须完成你的代码

您的页面和iframe都可以访问window.location.hash



这就是为什么你可以把iframe函数的名字放在主url af中你的行动例如点击按钮



在iframe中你可以拥有上面的代码

iframe每200毫秒检查一次网址,如果可以找到一个函数名,通过eval函数,它可以正常运行



提到你必须访问iframe代码来做和调用iframe的函数您的页面.....




you have to complete your code
your page and the iframe both can access the window.location.hash

thats why you can put the name of the iframe function in the main url after your action for example clicking the button

in the iframe you can have the above code
iframe check the url every 200msecond , and if can find a function name , by eval the function , it can run properly

mention that you have to access the iframe code source to do and call the function of iframe from your page.....


您可以按照我的提示与跨域IFrame的通信 - 跨浏览器解决方案 [ ^ ],但您需要在iFrame页面上定义一些事件监听器。
You can follow my Tip Communication with Cross Domain IFrame - A Cross Browser Solution[^], but you need to define some Event Listener on the iFrame page.


这篇关于如何调用属于不同域的iframe中的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆