admin管理员组文章数量:1356716
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 badges1 Answer
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.
本文标签: JavascriptjQuery calling function in another frameStack Overflow
版权声明:本文标题:JavascriptjQuery: calling function in another frame - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743982847a2571153.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论