2011-05-29 54 views
0

如何隱藏另一幀的內容。我的意思是:如何隱藏另一幀的子幀的幀?

Parent 
Frame F1 
    Page P1 
Frame F2 
    Page P2 

我從P2想隱瞞使用JQuery的JavaScript中的幀F1。

+0

你的意思是你怎麼從內P2的JS進入F1? – 2011-05-29 14:15:31

+0

是的,我想隱藏只訪問它 – Jose 2011-05-29 14:15:55

+0

所有這些幀來自同一個域? – 2011-05-29 14:18:24

回答

1

你可以這樣做:

iframe的access.html

<html> 
<head> 
<style type="text/css"> 
</style> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script> 
<script type="text/javascript"> 
</script> 
</head> 
<body> 
<iframe src="iframe1.html" id="iframe1"></iframe> 
<iframe src="iframe2.html" id="iframe2"></iframe> 
</body> 
</html> 

iframe1.html

<html> 
<head> 
<style type="text/css"> 
</style> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script> 
<script type="text/javascript"> 
</script> 
</head> 
<body> 
<h1>Iframe 1</h1> 
</body> 
</html> 

iframe2.html

<html> 
<head> 
<style type="text/css"> 
</style> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script> 
<script type="text/javascript"> 
alert('Hide Iframe 1'); 
window.parent.document.getElementById('iframe1').style.display = 'none'; 
</script> 
</head> 
<body> 
<h1>Iframe 2</h1> 
</body> 
</html> 

http://jfcoder.com/test/iframe-access.html

注意

這也將工作(何塞指出):

window.parent.document.getElementById('framesetID').rows = "0%,*"; 
+0

感謝您的答案。內容被清除,但框架itslelf不被隱藏。 – Jose 2011-05-29 14:28:28

+0

@Jose - 你在說這裏? http://jfcoder.com/test/iframe-access.html – 2011-05-29 14:30:50

+0

不,關於我的代碼。 – Jose 2011-05-29 14:31:19