activeDesktop2.jsp
包含两个<iframe><div id="headerTools">
<iframe style="border 0px none;width:100%;height:25" scrolling="no" frameborder="no" id="headerToolsIFrame1" src="tools.jsp"></iframe>
</div><!--聊天-->
 <div id="west">
<iframe style="border 0px none;width:100%;height:100%" scrolling="auto" frameborder="no" id="westIFrame" src="hiddenFrameForChat.jsp"></iframe>
</div>我想在
tools.jsp中访问hiddenFrameForChat.jsp中的函数opengroupchat()该怎么写?
我在tools.jsp中试着写parent.westIFrame.opengroupchat()发现错了.
那为知道帮忙解答一下,谢谢.

解决方案 »

  1.   

    跨window访问函数的方式,其实是JavaScript表达式的命名空间问题。
    1。通常,你在页面中定义了如下函数,
    <script type='text/javascript'>
    function opengroupchat(){};
    </script>
    其实"opengroupchat"它是从属于匿名的<script/>对象的;
    如果你在其它页面tools.jsp中要访问,有两种方式:
    1。顺藤摸瓜parent.westIFrame.document.scripts[匿名script的索引].opengroupchat();
    2.重构函数
    上面可改为:
    <script type='text/javascript'>
    window.opengroupchat = function (/*string*/arg1, /*string*/arg2){
    };
    </script>则可以如下访问:
    parent.westIFrame.window.opengroupchat(你的参数);