Heim  >  Artikel  >  Web-Frontend  >  iFrame的妙用_html/css_WEB-ITnose

iFrame的妙用_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:06:38830Durchsuche

 (作者: Glen,返利网资深工程师,曾在EA等公司任职)

  最近工作有个在项目-布兜收藏夹。简言之就是将喜欢的图片收藏到布兜页面上来,这其中用到了很多关于iframe的方面,总结如下:

  1. 作为弹出层铺底覆盖

  大家如果做过那种黑色遮罩盖住整张页面,而碰巧用户用的是IE6,更碰巧的是页面上有select元素,那就有得头疼了(原理就不在这里赘述了)。我们会发现弹出的DIV没法遮住select, 轮到我们的iframe出场了。逻辑如下:

  • 与弹出div同级放入iframe
  • 保证iframe的 z-index小于弹层div z-index
  • 增加window resize和scroll事件, 保证iframe能盖住整张页面
  •   部分代码

     var iframe = U.isie6() ? '<iframe style="position:absolute;left:0;top:0;z-index:2000000;filter:Alpha(opacity=0); width:100%;height:' + ds.height + '" frameborder="0"></iframe>' : ''; $container.append(iframe).appendTo($body);

      2.  跨域写入cookie

      有 a.com和b.com两个domain。在某些条件下b的部分功能会出现在a页面上。 有时需要操作a页面的时候对b.com domain的cookie做一些操作以方便用户下次访问。我们只需要在a页面加入一个iframe(动态或固定)即可,src属性指向b的一张代理页 面,在这张页面执行cookie操作即可。

    Stellungnahme:
    Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn