2012-11-27 2 views
0

나는 샘플 코드를 가지고 : index.html을자바 스크립트를 사용하여 iframe에서 값을 추가하는 방법은 무엇입니까?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns:fb="http://ogp.me/ns/fb#"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>index</title> 
</head> 
<body> 
<input type="text" value="" name="test" id="text_input"> 
<iframe src="iframe.html"> 
</body> 
</html> 

그리고

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns:fb="http://ogp.me/ns/fb#"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>iframe</title> 
<script> 
function getValue(text) { 
    document.getElementById('text_input').value = text; 
} 
</script> 
</head> 
<body> 
<a href="#" onclick="getValue('test');">Click</a> 
</body> 
</html> 

iframe.html에서 태그에 클릭이, 값 "텍스트"어떻게 from iframe to index.html에 전달 될 수없는 경우 고쳐?

답변

1

parent을 사용하면 부모 창을 iframe으로 가져올 수 있습니다. 사용해보기

function getValue(text) { 
    parent.document.getElementById('text_input').value = text; 
} 
관련 문제