我的广告代码页,给别人iframe使用,我想获取使用广告代码页的父页面的地址,使用了下面的代码
<iframe width="960" height="90" frameborder="0" scrolling="no" src="" onload="if(this.src=='')this.src='http://ad.abc.com/?US=C100086A20091022015421&Frm='+escape(window.location.href);"></iframe>
通过escape(window.location.href)获取页面的地址,在IE中可以,但是在FireFox中就不成了,因为在FireFox中,this.src获取的是父窗口的地址,不为空,就不能执行后面的脚本了,如果去掉判断if(this.src==''),被嵌入的页面就在那里不停的加载,不知道怎么解决了。在线等高手解决一下吧
<iframe width="960" height="90" frameborder="0" scrolling="no" src="" onload="if(this.src=='')this.src='http://ad.abc.com/?US=C100086A20091022015421&Frm='+escape(window.location.href);"></iframe>
通过escape(window.location.href)获取页面的地址,在IE中可以,但是在FireFox中就不成了,因为在FireFox中,this.src获取的是父窗口的地址,不为空,就不能执行后面的脚本了,如果去掉判断if(this.src==''),被嵌入的页面就在那里不停的加载,不知道怎么解决了。在线等高手解决一下吧
if(this.src=='' || this.src=window.location.href) //this.src=''
<script>var openflag=false;</script>
<iframe width="960" height="90" frameborder="0" name="aaa" scrolling="no" src="" onload="if(!openflag){this.src='http://ad.abc.com/?US=C100086A20091022015421&Frm='+escape(window.location.href);openflag=true}"></iframe>
<iframe width="960" height="90" frameborder="0" scrolling="no" src="" onload="getSrc(this)"></iframe>
function getSrc(_this)
{
alert(_this.src);
if(_this.src=='')
_this.src='http://ad.abc.com/?US=C100086A20091022015421&Frm='+escape(window.location.href);
}
<iframe width="960" height="90" frameborder="0" scrolling="no" src="http://www.baidu.com/" onload="if(this.src=='http://www.baidu.com/'){this.src='http://ad.abc.com/?US=C100086A20091022015421&Frm='+escape(window.location.href);}"></iframe>