控制框架內部內容跟框架內部控制外部的JS代碼

本文轉載自:http://itbaiduwang.com/q-45.html  IT擺渡網--一個按難度收費的IT程序員實時問答系統

案例一:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>框架控制</title>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script type="text/javascript">document.domain = '127.0.0.1:81';</script><!--網址,不帶http:// 必須要這句,不然沒用哦-->
</head>
<body>
<div id="login" style="display:none;"><a href="javascript:;" οnclick="$(window.frames['iframe1'].document).find('#h').css('display','none');">點擊</a></div>
<iframe src="b.html" id="iframe1" name="iframe1" width="500" height="50"></iframe>
</body>
</html>


案例二:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>框架控制</title>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script type="text/javascript">document.domain = '127.0.0.1:81';</script><!--網址,不帶http:// 必須要這句,不然沒用哦-->
</head>
<body>
<a href="javascript:;" οnclick="$('#login',window.parent.document).css('display','block');">點擊</a>
<a href="javascript:;" οnclick="window.top.location.reload();">刷新</a>
<div id="h" style="display:block;">這裏要被隱藏</div>
</body>
</html>


案例三:(在框架內調用框架外的方法)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>框架控制</title>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script type="text/javascript">document.domain = '127.0.0.1:81';</script><!--網址,不帶http:// 必須要這句,不然沒用哦-->


<script>

function akui()
{
alert("ddd");
}

</script>

</head>
<body>
<div id="login" ><a href="javascript:;" οnclick="$(window.frames['iframe1'].document).find('#h').css('color','red');">點擊</a></div>
<iframe src="b.html" id="iframe1" name="iframe1" width="500" height="50"></iframe>
</body>
</html>


案例四:(在框架內調用框架外的方法)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>框架控制</title>

<script type="text/javascript">document.domain = '127.0.0.1:81';</script><!--網址,不帶http:// 必須要這句,不然沒用哦-->
</head>
<body>
<a href="javascript:;" οnclick="parent.window.akui();">點擊</a>
<a href="javascript:;" οnclick="window.top.location.reload();">刷新</a>
<div id="h" style="display:block;">這裏要被隱藏</div>
</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章