firefox返回时iframe的显示bug的解决方法_经验交流
<script>//<![CDATA[
if(getCookie('firefoxIframe')){
document.write('<p id="addAd"><a href="cookie.html">点击这里删除这个iframe');
document.write('<iframe height="120" width="300" marginheight="0" marginwidth="0"
frameborder="0" src="nAdPre.swf">');
}else{
document.write('<p id="addAd"><a href="cookie.html">点击这里增加一个iframe');
}
//]]></script>
打开Bug演示,由于cookie不存在,显示的三个flash都是通过Iframe实现的
点击“点击这里增加一个iframe广告”,跳转到一个新的页面写入名为firefoxIframe的Cookie
点击“返回”或者浏览器的返回按钮,回到Bug演示页面,发现iframe里面的flash错位,即位置2的iframe链接的flash并没有载入,显示的是位置3的flash,位置3的显示的是位置4的flash,位置4的flash却依旧存在。
关闭标签页(不是关闭整个浏览器,如果关闭整个浏览器Cookie也失效)或新打开一个标签页重新载入该页面,4个Iframe正常显示4个flash
此时如果点击“点击这里删除这个iframe广告”,跳转到新页面删除Cookie,返回也发现Iframe中的flash错位
如果写入Cookie或者删除Cookie时,不通过浏览器的返回,直接通过网址访问,则不会出现错位
简单分析和解决方案
似乎Firefox返回时,Javascript重新执行了,但是Iframe并未依据src属性重新载入,而是给Iframe和src以类似编号似的配对,而由于返回时Javascript的执行,导致Iframe多了一个(或少了一个),这就导致后面的配对错位。
以上仅为猜测,但这的确是Firefox(2.0.0.3)的一个bug,IE返回时Javascript重新执行,并且Iframe的依据src重新载入,Opera返回时Javascript不重新执行,页面没有变化。
解决方案是在文本中增加一个隐藏的Iframe来占位,上面代码修改如下代码如下:
document.write('<p><a>点击这里增加一个iframe</a></p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/ai/2075" title="九歌"><img
src="https://img.php.cn/upload/ai_manual/000/000/000/175680183660656.png" alt="九歌" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/ai/2075" title="九歌" class="overflowclass">九歌</a>
<p class="overflowclass">一款专注于中文诗歌创作的人工智能写作系统,可围绕主题和表达需求辅助生成具有诗歌形式的中文文本。</p>
</div>
<a rel="nofollow" href="/ai/2075" title="九歌" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div>');
//把上面的代码修改成为
document.write('<iframe></iframe>');
document.write('<p><a>点击这里增加一个iframe</a></p>');
以上就是Firefox返回时Iframe的显示Bug的解决方法_经验交流的内容,更多相关内容请关注PHP中文网(www.php.cn)!










