<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FoxLing - 前端开发 &#187; 跨域</title>
	<atom:link href="http://foxling.org/tag/%e8%b7%a8%e5%9f%9f/feed/" rel="self" type="application/rss+xml" />
	<link>http://foxling.org</link>
	<description>不积跬步 无以至千里</description>
	<lastBuildDate>Sat, 19 Nov 2011 16:29:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>小技巧，跨域关闭iframe</title>
		<link>http://foxling.org/js-ajax-dom/remove-iframe-cross-domain/</link>
		<comments>http://foxling.org/js-ajax-dom/remove-iframe-cross-domain/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 13:35:52 +0000</pubDate>
		<dc:creator>FoxLing</dc:creator>
				<category><![CDATA[JS/AJAX/DOM]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[跨域]]></category>

		<guid isPermaLink="false">http://foxling.cn/?p=420</guid>
		<description><![CDATA[示例 DEMO猛击这里 解决方法 直接看代码吧： function Dialog(){ this.panel = document.createElement('div'); this.panel.id = 'bmPanel'; this.panel.style.position = 'absolute'; this.panel.style.right = '0px'; this.panel.style.right = this.scrollTop() + 'px'; this.panel.style.zIndex = 100000; this.panel.style.margin = '10px'; this.panel.style.width = '200px'; this.panel.style.height = '200px'; this.panel.style.border = '5px solid #CCC'; this.panel.innerHTML = '&#60;iframe id="bmIframe" ' + 'token="1" onload="c = this.getAttribute(\'token\'); if (c==3) {this.parentNode.parentNode.removeChild(this.parentNode)} this.setAttribute(\'token\',++c);"' + [...]]]></description>
			<content:encoded><![CDATA[<h3>示例</h3>
<p><a href="/examples/close-iframe/remove-iframe.html">DEMO猛击这里</a></p>
<h3>解决方法</h3>
<p>直接看代码吧：</p>
<pre>
function Dialog(){
	this.panel = document.createElement('div');
	this.panel.id = 'bmPanel';
	this.panel.style.position = 'absolute';
	this.panel.style.right = '0px';
	this.panel.style.right = this.scrollTop() + 'px';
	this.panel.style.zIndex = 100000;
	this.panel.style.margin = '10px';
	this.panel.style.width = '200px';
	this.panel.style.height = '200px';
	this.panel.style.border = '5px solid #CCC';
	this.panel.innerHTML = '&lt;iframe id="bmIframe" '
		+ 'token="1" onload="c = this.getAttribute(\'token\'); if (c==3) {this.parentNode.parentNode.removeChild(this.parentNode)} this.setAttribute(\'token\',++c);"'
		+ 'name="bmIframe" src="main.html" scrolling="no" frameborder="0" style="width:100%; height:100%; '
		+ 'border:1px; padding:0px; margin:0px"&gt;&lt;/iframe&gt;';
}

Dialog.prototype.show = function(){
	document.body.appendChild(this.panel);
}

Dialog.prototype.scrollTop = function (){
	return document.documentElement &#038;&#038; document.documentElement.scrollTop || document.body.scrollTop;
}
</pre>
<p>注意iframe这一行：</p>
<pre>
onload="c = this.getAttribute(\'token\'); if (c==3) {this.parentNode.parentNode.removeChild(this.parentNode)} this.setAttribute(\'token\',++c);"
</pre>
<p>iframe里的关闭按钮链接一个简单的页面，通过不停地提交表单触发load事件，让token累加：</p>
<pre>
&lt;body onload="document.getElementById('close').submit()"&gt;
	&lt;form id="close" action="closeing.html" method="get"&gt;&lt;/form&gt;
&lt;/body&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://foxling.org/js-ajax-dom/remove-iframe-cross-domain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

