Javascript / jQuery:在另一个框架中调用函数 [英] Javascript/jQuery: calling function in another frame

查看:81
本文介绍了Javascript / jQuery:在另一个框架中调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是DOM和JavaScript的新手,在尝试从顶层框架或Firebug的上下文中调用框架中定义的函数时遇到了一些问题。

I'm new to the DOM and JavaScript and hitting on some problems when trying to call a function defined in a frame from the context of the top-level frame or Firebug.

鉴于以下框架集:

<html>
    <body>
    <frameset cols="*" rows="81,*">
        <frame id="topFrame" tabindex="1" name="topFrame" noresize="noresize" scrolling="No" src="hometop.aspx"/> 
        <frameset border="0" cols="214,*" frameborder="no" framespacing="0">
            <frameset border="0" cols="*" frameborder="no" framespacing="0" rows="70,*">
                <frame tabindex="-1" id="chatFrame" name="chatFrame" scrolling="No" noresize="noresize" src=""/>
                <frame tabindex="-1" id="leftFrame" name="leftFrame" noresize="noresize" src="leftFrame.aspx"/>
            </frameset> 
            <frame tabindex="-1" id="mainFrame" name="mainFrame" src=""/>
        </frameset> 
        <noframes>Your browser does not support frameset.</noframes> 
    </frameset>
    </body>
</html>

我正在尝试编写一个javascript钩子,它将调用中定义的javascript函数# leftFrame 首次打开上述文档时。我在加载 jQuery 的Firebug会话中执行此操作。

I'm trying to write a javascript hook that will call a javascript function defined in #leftFrame when the above document is first opened. I'm performing this in a Firebug session with jQuery loaded.

jQuery(#leftFrame )返回一个框架DOM元素。现在,我想在框架的上下文中执行我的函数( openLink ,在leftFrame.aspx中的普通旧脚本标记中定义)。我的理解是该函数将是 leftFrame 的文档元素下的DOM节点。但是我无法抓住框架的文件。

jQuery("#leftFrame") returns a frame DOM element. Now I'd like to execute my function (openLink, defined in plain old script tag in leftFrame.aspx) in the context of the frame. My understanding is that the function will be a DOM node under the leftFrame's document element. However I can't get hold of the frame's document.

我试过:

 jQuery("#leftFrame").document
 jQuery("#leftFrame").contentDocument
 jQuery("#leftFrame").find("html")

同样在Firebug中检查DOM树时,我看不到任何 openLink 功能我期待的DOM节点。

Also when inspecting the DOM tree in Firebug I can't see the openLink function under any DOM nodes as I'd expect.

任何人都可以帮助我吗?

Can anyone help me out?

推荐答案

$('#leftFrame')[0].contentWindow.document
$('#leftFrame')[0].contentWindow.functionName()

以上情况应该有效。 jQuery的 contents()仅适用于iframe节点,所以你必须像那样引用它。

The above should work. jQuery's contents() only works on the iframe node so you'll have to reference it like that.

这篇关于Javascript / jQuery:在另一个框架中调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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