问题描述
|
如何隐藏另一个框架的内容。我的意思是:
Parent
Frame F1
Page P1
Frame F2
Page P2
我想从P2使用JQuery的Java隐藏框架F1。
解决方法
你可以这样做:
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
注意
这也将起作用(如Jose指出的那样):
window.parent.document.getElementById(\'framesetID\').rows = \"0%,*\";