<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>https://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>https://jackxiang.com/post//</link>
<title><![CDATA[[实践Ok]父页面调用iframe里的js函数相关例程，Iframe之间通讯研究。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Wed, 06 Mar 2013 01:56:15 +0000</pubDate> 
<guid>https://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	前些天项目碰到这个问题，在ie下可以直接调用iframe里的js函数 <br/>如: <br/>document.getElementById(&#039;iframedemo&#039;).targetfunction(); <br/>但是这段代码在firefox下报错，于是上google搜索，发现一个解决办法，在ie和firefox <br/>下均工作正常,代码如下: <br/>document.getElementById(&#039;iframedemo&#039;).contentWindow.demofunction(); <br/>其中iframedemo是iframe的id<br/><br/>来自：http://www.cnblogs.com/lovelace821/archive/2009/08/03/1537777.html<br/>补充：<br/>contentWindow属性是指指定的frame或者iframe所在的window对象<br/>在IE中iframe或者frame的contentWindow属性可以省略，但在Firefox中如果要对iframe对象进行编辑则<br/>必须指定contentWindow属性。<br/><br/><br/>主要知识点<br/> <br/>1：document.getElementById(&quot;ii&quot;).contentWindow 得到iframe对象后，就可以通过contentWindow得到iframe包含页面的window对象，然后就可以正常访问页面元素了；<br/> <br/>2：$(&quot;#ii&quot;)[0].contentWindow&nbsp;&nbsp;如果用jquery选择器获得iframe，需要加一个【0】；<br/> <br/>3：$(&quot;#ii&quot;)[0].contentWindow.$(&quot;#dd&quot;).val() 可以在得到iframe的window对象后接着使用jquery选择器进行页面操作;<br/> <br/>4：$(&quot;#ii&quot;)[0].contentWindow.hellobaby=&quot;dsafdsafsdafsdafsdafsdafsadfsadfsdafsadfdsaffdsaaaaaaaaaaaaa&quot;; 可以通过这种方式向iframe页面传递参数，在iframe页面window.hellobaby就可以获取到值，hellobaby是自定义的变量；<br/> <br/>5：在iframe页面通过parent可以获得主页面的window，接着就可以正常访问父亲页面的元素了；<br/> <br/>6：parent.$(&quot;#ii&quot;)[0].contentWindow.ff; 同级iframe页面之间调用，需要先得到父亲的window，然后调用同级的iframe得到window进行操作；<br/><br/>来自：http://bakcom.iteye.com/blog/1757449<br/><br/><br/><br/>找了一篇文章的实践情况如下：<br/>实践内容来自：http://bakcom.iteye.com/blog/1757449<br/>main.html<br/><textarea name="code" class="JS" rows="15" cols="100">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
&lt;title&gt;显示图表&lt;/title&gt;
&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;&nbsp;&nbsp;
&lt;script&gt;!window.jQuery &amp;&amp; document.write(&#039;&lt;script src=&quot;js/jquery-1.4.2.min.js&quot;&gt;&lt;&#92;/script&gt;&#039;)&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/script&gt;&nbsp;&nbsp;
&lt;script type=&quot;text/javascript&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;var gg=&quot;dsafdsafdsafdsafsdaf&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;function ggMM() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;2222222222222222222222222222222&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;function callIframeMethod() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//document.getElementById(&quot;ii&quot;).contentWindow.test();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(&quot;#ii&quot;)[0].contentWindow.test(); //用jquery调用需要加一个[0]
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;function callIframeField() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert($(&quot;#ii&quot;)[0].contentWindow.ff);
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;function callIframeHtml() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert($(&quot;#ii&quot;)[0].contentWindow.$(&quot;#dd&quot;).val());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//alert($(&quot;#ii&quot;)[0].contentWindow.document.getElementById(&quot;dd&quot;).value);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//alert($(&quot;#ii&quot;)[0].contentWindow.document.getElementById(&quot;dd&quot;).value);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&#125;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;function giveParameter() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(&quot;#ii&quot;)[0].contentWindow.hellobaby=&quot;dsafdsafsdafsdafsdafsdafsadfsadfsdafsadfdsaffdsaaaaaaaaaaaaa&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href=&quot;#&quot; onClick=&quot;giveParameter();&quot;&gt;参数传递&lt;/a&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href=&quot;#&quot; onClick=&quot;callIframeMethod();&quot;&gt;调用子iframe方法&lt;/a&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href=&quot;#&quot; onClick=&quot;callIframeField();&quot;&gt;调用子iframe变量&lt;/a&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href=&quot;#&quot; onClick=&quot;callIframeHtml();&quot;&gt;调用子iframe组件&lt;/a&gt;&lt;/br&gt;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;iframe id=&quot;ii&quot; src=&quot;frame.htm&quot; width=&quot;100%&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;iframe id=&quot;new&quot; src=&quot;newFrame.htm&quot; width=&quot;100%&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;
&lt;/body&gt;
&lt;/html&gt;
</textarea><br/><br/>frame.htm<br/><textarea name="code" class="JS" rows="15" cols="100">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
&lt;title&gt;显示图表&lt;/title&gt;
&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;&nbsp;&nbsp;
&lt;script&gt;!window.jQuery &amp;&amp; document.write(&#039;&lt;script src=&quot;js/jquery-1.4.2.min.js&quot;&gt;&lt;&#92;/script&gt;&#039;)&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/script&gt;&nbsp;&nbsp;
&lt;script type=&quot;text/javascript&quot;&gt;
 
var ff=&quot;adfdasfdsafdsafdsaf&quot;;
function test() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;alert($(&quot;#dd&quot;).val());
&#125;
function callMainField() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;alert(parent.gg);
&#125;
function callMainMethod() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;parent.ggMM();
&#125;
function callMainHtml() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;alert(parent.$(&quot;#ii&quot;).attr(&quot;id&quot;));
&#125;
function getParameter() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;alert(window.hellobaby);
&#125;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href=&quot;#&quot; onClick=&quot;getParameter();&quot;&gt;接受参数&lt;/a&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href=&quot;#&quot; onClick=&quot;callMainMethod();&quot;&gt;调用子iframe方法&lt;/a&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href=&quot;#&quot; onClick=&quot;callMainField();&quot;&gt;调用主窗口变量&lt;/a&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href=&quot;#&quot; onClick=&quot;callMainHtml();&quot;&gt;调用子iframe组件&lt;/a&gt;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&lt;input id=&quot;dd&quot; type=&quot;text&quot; value=&quot;1111111111&quot;/&gt;
&lt;/body&gt;
&lt;/html&gt;
</textarea><br/><br/>newFrame.htm：<br/><textarea name="code" class="JS" rows="15" cols="100">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
&lt;title&gt;显示图表&lt;/title&gt;
&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;&nbsp;&nbsp;
&lt;script&gt;!window.jQuery &amp;&amp; document.write(&#039;&lt;script src=&quot;js/jquery-1.4.2.min.js&quot;&gt;&lt;&#92;/script&gt;&#039;)&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/script&gt;&nbsp;&nbsp;
&lt;script type=&quot;text/javascript&quot;&gt;
function callLevelFrame() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;var ff=parent.$(&quot;#ii&quot;)[0].contentWindow.ff;
&nbsp;&nbsp;&nbsp;&nbsp;alert(ff);
&#125;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href=&quot;#&quot; onClick=&quot;callLevelFrame();&quot;&gt;调用兄弟iframe&lt;/a&gt;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;input id=&quot;nn&quot; type=&quot;text&quot; value=&quot;sdafsdfsa&quot;/&gt;
&lt;/body&gt;
&lt;/html&gt;
</textarea>
]]>
</description>
</item><item>
<link>https://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践Ok]父页面调用iframe里的js函数相关例程，Iframe之间通讯研究。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>