如何隐藏另一帧的孩子的框架?

时间:2011-05-29 14:13:33

标签: javascript html iframe

如何隐藏另一个内容的框架。我的意思是:

Parent
 Frame F1
   Page P1
 Frame F2
   Page P2

我希望P2使用JQuery的Javascript隐藏帧F1。

1 个答案:

答案 0 :(得分: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%,*";