JavaScript邮箱系统开发(四)

一、判断显示或创建iframe

function iframeJudge(options){
    var elem = options.elem,
      href = options.href,
      id = options.id,
      li = $('#B_history li[data-id='+ id +']');

    if(li.length > 0) {
      //如果是已经存在的iframe,则显示并让选项卡高亮,并不显示loading
      var iframe = $('#iframe_'+ id);
      $('#loading').hide();
      li.addClass('current');
      if( iframe[0].contentWindow && iframe[0].contentWindow.location.href !== href ) {
         iframe[0].contentWindow.location.href = href;
      }
      
      $('#B_frame iframe').hide();
      $('#iframe_'+ id).show();
      showTab(li);       //计算此tab的位置,如果不在屏幕内,则移动导航位置
    } else {
      //创建一个并加以标识
      var iframeAttr = {
	src		: href,
	id		: 'iframe_' + id,
	frameborder	: '0',
	scrolling	: 'auto',
	height		: '100%',
	width		: '100%'
      };

      var iframe = $('<iframe/>').prop(iframeAttr).appendTo('#B_frame');
		
      $(iframe[0].contentWindow.document).ready(function() {
	$('#B_frame iframe').hide();
	$('#loading').hide();
	
	var li = $('<li tabindex="0"><span><a>'+ elem.html() +'</a><a class="del" title="关闭此页">关闭</a></span></li>').attr('data-id',id).addClass('current');
	
	li.siblings().removeClass('current');
	li.appendTo('#B_history');
	showTab(li);       //计算此tab的位置,如果不在屏幕内,则移动导航位置
     });
   }
}



你可能感兴趣的:(JavaScript邮箱系统开发(四))