<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <title>首页tab</title> <%@include file="/wdk/theme/je/module/public/common.jsp"%> <script type="text/javascript"> var index_tabs; var index_tabsMenu; var tabs_all; //所有的页签 var tab_border = false; var tab_duplicate = false; var tab_islaze = false; //是否延迟加载 var _tabid; var _gfvid; function doInit(){ index_tabs = $('#tabs').tabs({ fit : true, border : tab_border, onDblClick:function(e,title){ alert('aaa title='+title); }, onContextMenu : function(e, title) { e.preventDefault(); index_tabsMenu.menu('show', { left : e.pageX, top : e.pageY }).data('tabTitle', title); }, tools : [ { iconCls : 'database_refresh', handler : function() { var href = index_tabs.tabs('getSelected').panel('options').href; if (href) {/*说明tab是以href方式引入的目标页面*/ var index = index_tabs.tabs('getTabIndex', index_tabs.tabs('getSelected')); index_tabs.tabs('getTab', index).panel('refresh'); } else {/*说明tab是以content方式引入的目标页面*/ var panel = index_tabs.tabs('getSelected').panel('panel'); var frame = panel.find('iframe'); try { if (frame.length > 0) { for ( var i = 0; i < frame.length; i++) { frame[i].contentWindow.document.write(''); frame[i].contentWindow.close(); frame[i].src = frame[i].src; } if (navigator.userAgent.indexOf("MSIE") > 0) {// IE特有回收内存方法 try { CollectGarbage(); } catch (e) { } } } } catch (e) { } } } }, { iconCls : 'delete', handler : function() { var index = index_tabs.tabs('getTabIndex', index_tabs.tabs('getSelected')); var tab = index_tabs.tabs('getTab', index); if (tab.panel('options').closable) { index_tabs.tabs('close', index); } else { $.messager.alert('提示', '[' + tab.panel('options').title + ']不可以被关闭!', 'error'); } } } ] }); index_tabsMenu = $('#index_tabsMenu').menu({ onClick : function(item) { var curTabTitle = $(this).data('tabTitle'); var type = $(item.target).attr('title'); if (type === 'refresh') { index_tabs.tabs('getTab', curTabTitle).panel('refresh'); return; } if (type === 'close') { var t = index_tabs.tabs('getTab', curTabTitle); if (t.panel('options').closable) { index_tabs.tabs('close', curTabTitle); } return; } var allTabs = index_tabs.tabs('tabs'); var closeTabsTitle = []; $.each(allTabs, function() { var opt = $(this).panel('options'); if (opt.closable && opt.title != curTabTitle && type === 'closeOther') { closeTabsTitle.push(opt.title); } else if (opt.closable && type === 'closeAll') { closeTabsTitle.push(opt.title); } }); for ( var i = 0; i < closeTabsTitle.length; i++) { index_tabs.tabs('close', closeTabsTitle[i]); } } }); /* $(window).resize(function () { $('#tabs').tabs({ width: $("#tabs").parent().width(), height: document.documentElement.clientHeight-1 }); }); $(function() { $('#tabs').tabs({ width: $("#tabs").parent().width(), height: document.documentElement.clientHeight-1 }); }); */ }; //增加一个页签 function tab_add(jtab){ if(jtab){ //去除重名 var _titlenum = 0; //同名的title数量 var _title = jtab.title; var tabs = $("#tabs").tabs('tabs'); for(var i=0;i<tabs.length;i++){ var tab = tabs[i]; var title = tab.panel('options').title; if(title == _title){ _titlenum++; }else{ var titmp = title.substring(0,_title.length); if(titmp==_title){ var tinumstr = title.substring(_title.length,title.length); if(/^[(]\d+[)]$/ig.test(tinumstr)){ //如果后面是形如 (13) _titlenum++; } } } } if(_titlenum>0){ if(tab_duplicate){ _title += '('+_titlenum+')'; }else{ //alert('已打开相同页面'); $('#tabs').tabs('select',_title);//如果已经存在页面则切换到该tab页 return false; } } var _closable = true; if('string'==typeof(jtab.closable)){ _closable = 'false'==jtab.closable?false:true; }else{ _closable = jtab.closable; } var _src = jtab.url; if(-1==_src.indexOf("?")){ _src += "?tabid="+_tabid+"&tabtitle="+_title+"&gfvid="+_gfvid; }else{ _src += "&tabid="+_tabid+"&tabtitle="+_title+"&gfvid="+_gfvid; } var _content = '<iframe id="'+_title+'" name="'+_title+'" src="'+_src+'" width="100%" height="98%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" ></iframe>'; if(jtab.islaze){ _content = ''; } $('#tabs').tabs('add',{ title:_title, content:_content, closable:_closable, selected:jtab.selected?jtab.selected:false }); } } function init(strparam){ var jparam = $.str2json(strparam); _tabid = jparam.tabid; _gfvid = jparam.gfvid; tabs_all = jparam.tabs; var _border = (('true'==jparam.border) || (true==jparam.border))?true:false; var _duplicate = (false==jparam.duplicate||'false'==jparam.duplicate)?false:true; //是否允许重复打开 tab_duplicate = _duplicate; var _islaze = (true==jparam.islaze||'true'==jparam.islaze)?true:false; //是否延迟加载 var _onLoad = jparam.onLoad?jparam.onLoad:null; var _onLoadSuccess = jparam.onLoadSuccess?jparam.onLoadSuccess:null; var _onSelect = jparam.onSelect?jparam.onSelect:null; var _onBeforeClose = jparam.onBeforeClose?jparam.onBeforeClose:null; var _onClose = jparam.onClose?jparam.onClose:null; var _onAdd = jparam.onAdd?jparam.onAdd:null; var _onUpdate = jparam.onUpdate?jparam.onUpdate:null; $('#tabs').tabs({ border :_border ,duplicate:_duplicate ,onLoad:function(panel){ if(_onLoad){ $.method_call(_onLoad,panel); } if(_onLoadSuccess){ $.method_call(_onLoadSuccess,panel); } } ,onSelect:function(title){ if(_onSelect){ $.method_call(_onSelect,title); } } ,onBeforeClose:function(title){ if(_onBeforeClose){ $.method_call(_onBeforeClose,title); } } ,onClose:function(title){ if(_onClose){ $.method_call(_onClose,title); } } ,onAdd:function(title){ if(_onAdd){ $.method_call(_onAdd,title); } } ,onUpdate:function(title){ if(_onUpdate){ $.method_call(_onUpdate,title); } } }); if(tabs_all){ for(var i=0;i<tabs_all.length;i++){ var jtab = tabs_all[i]; if(i>0){ //jtab.islaze = true; } tab_add(jtab); } } //给tab绑定双击关闭事件 $('#tabs').tabs('bindDblclick', function(index, title){ var t = $('#tabs').tabs('getTab', title); if (t.panel('options').closable) { $('#tabs').tabs('close', title); } }); //初始化默认选中第一条 $('#tabs').tabs('select',0); doInit(); } </script> </head> <body id="mybody" style="overflow:hidden;padding:0px;border:0px solid #000000;"> <div id="tabs" style="height:100%; width:100%;overflow: hidden;"> </div> </body> </html>