如何调用在子< frame>中指定的javascript函数 [英] How to call javascript function specified in a child <frame>

查看:111
本文介绍了如何调用在子< frame>中指定的javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



以下是父页面的常见HTML结构(index.html):

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD HTML 4.01 // ENhttp://www.w3。组织/ TR / HTML4 / strict.dtd> 
< html lang =en>
< head>
< / head>
< frameset rows =75px,*frameborder =0>
< frame name =frame1src =frames / frame1.html>
< frameset class =child_frameset>
< frame name =frame3src =frames / frame3.html>
< / frameset>
< / frameset>
< / html>

这里我是如何在子框架(frame3.html)上指定javascript函数的:

 <!DOCTYPE html> 
< html lang =en>
< head>
< script type =text / javascript>
函数helloWorld(){
alert('hello world!');
}
< / script>
< / head>
< body>
< h1>我是第3帧< / h1>
< / body>
< / html>

我的任务是调用 helloWorld()函数。如何做到这一点?

在此先感谢!

解决方案

您可以这样做:

  document.getElementById('frame3')。contentWindow.helloWorld(); 


I'm working on a accient project which based on and tags.

Here's the common HTML structure of the parent page (index.html):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>  
</head>
<frameset rows="75px,*" frameborder="0">
    <frame name="frame1" src="frames/frame1.html">
    <frameset class="child_frameset">
        <frame name="frame3" src="frames/frame3.html">
    </frameset>
</frameset>
</html>

Here how I specify the javascript function on the child frame (frame3.html):

<!DOCTYPE html>  
<html lang="en">  
<head>
    <script type="text/javascript">
        function helloWorld(){
            alert('hello world!');
        }
    </script>   
</head>
<body>
    <h1>I'm frame 3</h1>
</body>
</html>

My task is to call helloWorld() function. How do I do that?
Thanks in advance!

解决方案

You can do it like this:

document.getElementById('frame3').contentWindow.helloWorld();

这篇关于如何调用在子&lt; frame&gt;中指定的javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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