判断IFRAME是否全部载入完成 。调用iframe中的控件出现:错误:拒绝访问,代码:0 。Js/Jquery获取iframe中的元素 在Iframe中获取父窗体的元素方法

判断IFRAME是否全部载入完成  

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Pragma" contect="no-cache">
<title>新建网页 1</title>
</head>

<body>

<div id="info">正在加载.....</div>

<iframe id="auto_ifm" src="http://www.cnblogs.com/lhgstudio/archive/2010/10/24/1859946.html" scrolling= auto  width="100%" height="570" ></iframe>

 </body>


 <script>
/////////////////////////////////// 
 
var iframe = document.getElementById("auto_ifm");
    //iframe.src="http://www.cnblogs.com/lhgstudio/archive/2010/10/24/1859946.html";
    if (iframe.attachEvent){
        iframe.attachEvent("onload", function(){
            document.getElementById('info').innerHTML='加载完成!';
         });
    }else{
        iframe.onload = function(){
            document.getElementById('info').innerHTML='加载完成!';
        };
    }

infot(1);
function infot(j)
{
 if (document.getElementById('info').innerHTML=="加载完成!");
 //    { b_click();}
 else
     {
      j++;
      document.getElementById('info').innerHTML="正在加载....."+j+"秒";
      setTimeout("infot("+j+")",1000);
      
     }
}
//////////////////////////////

 
 </script>
</html>

=====================================================================================

调用iframe中的控件出现:错误:拒绝访问,代码:0  

//服务器地址 var webroot = "http://192.168.1.123:8080/tpccalendar/";//web.xml配置的servletvar service_pattern = "events_service";

 这是我的局域网ip地址
 
我自己测试时为localhost:8080....
 
而是用firefox和chrome就没有此问题
 
后来发现在我机器上输入<span style="white-space: pre;">192.168.1.123:8080就不会有问题...</span>
也就是换成IP:8080解决问题
 
总结原因为
 
<span style="color: #ff0000;">ie的安全级别过高</span>
 
<span style="font-family: arial, sans-serif, helvetica, tahoma; line-height: 18px;">工具--internet选项--安全--自定义级别--其它--通过域访问数据源</span>
 
设置一下就好了

========================================================================================

s/Jquery获取iframe中的元素 在Iframe中获取父窗体的元素方法  

在web开发中,经常会用到iframe,难免会碰到需要在父窗口中使用iframe中的元素、或者在iframe框架中使用父窗口的元素

js

在父窗口中获取iframe中的元素 

1、

格式:window.frames["iframe的name值"].document.getElementById("iframe中控件的ID").click();

实例:window.frames["ifm"].document.getElementById("btnOk").click();

2、

格式:

var obj=document.getElementById("iframe的name").contentWindow;

var ifmObj=obj.document.getElementById("iframe中控件的ID");

ifmObj.click();

实例:

var obj=document.getElementById("ifm").contentWindow;

var ifmObj=obj.document.getElementById("btnOk");

ifmObj.click();

在iframe中获取父窗口的元素

格式:window.parent.document.getElementById("父窗口的元素ID").click();

实例:window.parent.document.getElementById("btnOk").click();

jquery

在父窗口中获取iframe中的元素 

1、

格式:$("#iframe的ID").contents().find("#iframe中的控件ID").click();//jquery 方法1

实例:$("#ifm").contents().find("#btnOk").click();//jquery 方法1

2、

格式:$("#iframe中的控件ID",document.frames("frame的name").document).click();//jquery 方法2

实例:$("#btnOk",document.frames("ifm").document).click();//jquery 方法2

在iframe中获取父窗口的元素

格式:$('#父窗口中的元素ID', parent.document).click();

实例:$('#btnOk', parent.document).click();

default.htm==================================

<!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" />

<title>主页面</title>

<script type="text/javascript" language="javascript">

window.onload=function()
{
  document.getElementById("btnSet").onclick=setiframe;
}

function setiframe()

{
  if(document.getElementById)
    {
      var source=document.getElementById("source").value;
      var ifms=document.getElementById("ifm").contentWindow;
      ifms.document.getElementById("goal").value="OOOO";
      //ifms.document.getElementById("goal").value=source;

    }
}
function c1()
{
  alert("lll");
}
</script>

</head>

<body>

源:<input type="text" value="" id="source" name="source" />

<input type="button"  value="设置" id="btnSet" name="btnSet" />

<input type="button"  value="设置" id="btnSet0" name="btnSet0" onlick="c1();"/><br /></br />

<div>

<iframe id="ifm" name="ifm" src="default2.html" frameborder="0"></iframe>

</div>

</body>

</html>

default2.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" />

<title>iframe子页面</title>

</head>

<body>

目标:<input type="text" id="goal" name="goal" value="" />

</body>

</html>

<script type="text/javascript" language="javascript">

window.onload=Initgoal;

function Initgoal()

{

document.getElementById("goal").value=window.parent.document.getElementById("source").value;

}

</script>

猜你喜欢

转载自blog.csdn.net/hljqfl/article/details/86370095