JavascriptjQuery: calling function in another frame - Stack Overflow

I'm new to the DOM and JavaScript and hitting on some problems when trying to call a function defi

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.

Given the below frameset:

<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>

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") 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.

I've tried:

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

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?

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.

Given the below frameset:

<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>

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") 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.

I've tried:

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

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?

Share Improve this question asked Aug 17, 2010 at 9:29 chillitomchillitom 25.7k17 gold badges88 silver badges122 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7
$('#leftFrame')[0].contentWindow.document
$('#leftFrame')[0].contentWindow.functionName()

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743982848a4538801.html

相关推荐

  • JavascriptjQuery: calling function in another frame - Stack Overflow

    I'm new to the DOM and JavaScript and hitting on some problems when trying to call a function defi

    2天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信