日期:2014-05-16  浏览次数:20325 次

document.write("<iframe .. 的问题,请教
<html>
<head>
        <title> ajax.net </title>

        <script   language= "javascript ">
                function   w()
                {
                        document.write( " <iframe   id=\ "aa\ "   name=\ "aa\ "   scrolling=\ "no\ "   boder=\ "0\ "   marginheight=\ "0\ "   marginwidth=\ "0\ "   frameborder=\ "0\ "   src=\ "http://www.csdn.net\ "> </iframe> ");                
                }
                function   f()
                {
                        alert(document.frames( "aa ").document.body);
                        //这句为什么到不到值   ?   请教.
                }
        </script>

</head>
<body>

        <script   language= "javascript ">
                        w();
        </script>

        <div>
                <input   type= "button "   value= "src "   onclick= "f() "   />
        </div>
</body>
</html>

------解决方案--------------------
document.frames 是没有获取权限的

------解决方案--------------------
浏览器安全问题...
不允许获取...
------解决方案--------------------
说能访问滴肯定看错了,返回滴内容其实是父 document.body 的内容!!!

答案就是 iframe 的 document“拒绝访问”,不信就执行如下代码,L@_@K

<html>
<head>
<title> ajax.net </title>

<script language= "javascript ">
function w()
{
document.write( " <iframe id=\ "aa\ " name=\ "aa\ " scrolling=\ "no\ " boder=\ "0\ " marginheight=\ "0\ " marginwidth=\ "0\ " frameborder=\ "0\ " src=\ "http://www.csdn.net\ "> </iframe> ");
}
function f()
{
//alert(document.frames( "aa ").document.body);
//alert(document.frames[0]);
var p;
var result = " ";
for (p in document.frames[0])
{
if (p == "document ")
{
result += " <b style= 'color: red '> " + p + " </b> " + " : ";
}
else
{
result += p + " : ";
}
try
{