>  기사  >  웹 프론트엔드  >  js 상위 page_javascript 기술에서 하위 페이지를 사용하는 방법

js 상위 page_javascript 기술에서 하위 페이지를 사용하는 방법

WBOY
WBOY원래의
2016-05-16 15:20:461318검색

iframe은 매우 일반적으로 사용되는 html 요소입니다. 상위 페이지에서 하위 페이지를 사용하는 경우 어떻게 작성해야 할까요?
1. 상위 페이지 코드

<html>
<head>
<meta charset=" gb2312">
<title>父页面</title>
<script type="text/javascript">
function parentFunction() 
{
 alert('function in parent');
}
function callChild() 
{
 child.window.childFunction();
 /*
  child 为iframe的name属性值,
  不能为id,因为在FireFox下id不能获取iframe对象
 */
}
</script>
</head>
<body>
 <iframe name="child" src="./child.html" ></iframe>
</body>
</html>

2. iframe의 코드

<html>
<head>
<meta charset="gb2312">
<title>iframe代码</title>
<script type="text/javascript">
function childFunction() 
{
 alert('function in child');
}
function callParent() 
{
 parent.parentFunction();
}
</script>
</head>
<body>
</body>
</html>

위 두 코드는 상위 페이지와 하위 페이지에서 서로의 기능을 호출할 수 있으며 비교적 간단하므로 자세히 소개하지 않겠습니다.
이 기사가 JavaScript 프로그래밍을 배우는 데 도움이 되기를 바랍니다.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.