bootstrap添加iframe页

摘要:
改写自:https://www.cnblogs.com/yxgmagic/p/9637075.html效果图:˂script

改写自: https://www.cnblogs.com/yxgmagic/p/9637075.html

效果图:

bootstrap添加iframe页第1张

bootstrap添加iframe页第2张

bootstrap添加iframe页第3张bootstrap添加iframe页第4张
<div class="ibox float-e-margins">
    
    <div id="tabContainer"></div>
    
</div>
<script src="http://t.zoukankan.com/xxx.js"></script><!-- 引入下面js即可,自己命名 -->
<script>

    var iframe = $("#tabContainer").iframes({
        data: [ {
            id: 'home',
            text: '用户',
            url: "/mgr/user_edit/47",
            closeable: true}, {
            id: 'admineap2',
            text: '日志列表',
            url: "/menu/menu_edit/158",closeable: true}
        /*, {
            id: 'admineap',
            text: '部门',
            url: "/dept/dept_update/27"
        }, {
            id: 'menu',
            text: '菜单',
            url: "/menu/menu_edit/107"
        },{
            id: 'edit',
            text: '百度一下',
            url: "/blackboard/show",
            //closeable: true
        } */],
        //showIndex: 1,
        loadAll: false})

    iframe.addIframe({
        id: 'admineap',
        text: '部门',
        url: "/dept/dept_update/27",closeable: true});
    
    iframe.addIframe({
        id: 'menu',
        text: '菜单',
        url: "/menu/menu_edit/107",closeable: true});
    //iframe.showIframe('admineap');//根据数据属性id设置
</script>
View Code
bootstrap添加iframe页第5张bootstrap添加iframe页第6张
//xxx.js
(function($, window, document, undefined) {
    'use strict';

    var pluginName = 'iframes';
    var thisElement = '';
    var height = '500px';//以这种形式出现的iframe,必须设置高度,不能设置100%
    //入口方法
    $.fn[pluginName] = function(options) {
        var self = $(this);
        thisElement =self;
        if (this == null)
            return null;
        var data = this.data(pluginName);
        if (!data) {
            data = new BaseIframe(this, options);
            self.data(pluginName, data);
        }
        returndata;
    };


    var BaseIframe = function(element, options) {
        this.$element =$(element);
        this.options = $.extend(true, {}, this.default, options);
        this.init();
    }

    //默认配置
    BaseIframe.prototype.default ={
        showIndex: 0, //默认显示页索引
        loadAll: false//true=一次全部加在页面,false=只加在showIndex指定的页面,其他点击时加载,提高响应速度
}

    //结构模板
    BaseIframe.prototype.template ={
        div_tabs: '<div class="row content-tabs"></div>',
        nav_menuTabs: '<nav class="page-tabs J_menuTabs"></nav>',
        nav_a: '<a href="javascript:;"   data-  data-index="{1}" name="{2}">{3}</a>',//这里不能用id,id会追加代码到a标签内
        div_content: '<div   id="page-tabs"></div>',
        div_iframe: '<div   id="content-tabs"></div>',
        iframe: '<iframe   name="{0}" data-index="{1}"     src="http://t.zoukankan.com/{3}" frameborder="0" data-  seamless style="display: none;"></iframe>',
        a_close: '<i   title="关闭" data-id="{0}"></i>'}

    //初始化
    BaseIframe.prototype.init = function() {
        if (!this.options.data || this.options.data.length == 0) {
            console.error("请指定tab页数据");
            return;
        }
        //当前显示的显示的页面是否超出索引
        if (this.options.showIndex < 0 || this.options.showIndex > this.options.data.length - 1) {
            console.error("showIndex超出了范围");
            //指定为默认值
            this.options.showIndex = this.default.showIndex;
        }
        if(this.options.height){
            height = this.options.height;
        }
        //清除原来的tab页
        this.$element.html("");
        this.builder(this.options.data);
    }

    //使用模板搭建页面结构
    BaseIframe.prototype.builder = function(data) {
        var div_tabs = $(this.template.div_tabs);
        var nav_menuTabs = $(this.template.nav_menuTabs);
        var div_content = $(this.template.div_content);
        
        var div_iframe = $(this.template.div_iframe);
        for (var i = 0; i < data.length; i++) {
            //nav-tab
            var nav_a = $(this.template.nav_a.format(data[i].url,i,data[i].id ,data[i].text));
            //如果可关闭,插入关闭图标,并绑定关闭事件
            if(data[i].closeable) {
                var a_close = $(this.template.a_close.format(data[i].id));

                nav_a.append("&nbsp;");
                nav_a.append(a_close);
            }

            div_content.append(nav_a);
            

        }
        nav_menuTabs.append(div_content);
        div_tabs.append(nav_menuTabs);
        this.$element.append(div_tabs);
        this.$element.append(div_iframe);
        this.loadData();
    }
    
    /**
     * 添加Iframe
     * */BaseIframe.prototype.openIframe = function(dataUrl,menuName,dataIndex){
        //console.log("openiframe",this);
        //获取标识数据
        var flag = true;
        if (dataUrl == undefined || $.trim(dataUrl).length == 0)return false;
        thisElement.find("#content-tabs iframe").each(function(){
            //console.log('id',$(this).data('id'));
            //console.log('url',dataUrl);
            if($(this).data('id') ==dataUrl){
                
                flag = false;
            }
        });
        
        
        if(flag){
            
            var iframe = $(this.template.iframe.format(menuName,dataIndex,height,dataUrl,dataUrl));
            
            thisElement.find("#content-tabs").append(iframe);
        }
        BaseIframe.prototype.hidden_a(menuName);
        return false;
    }
    
    /**加载数据*/BaseIframe.prototype.loadData = function() {
        var data = this.options.data;
        //如果是当前页或者配置了一次性全部加载,否则点击tab页时加载
        for (var i = 0; i < data.length; i++) {
            if (this.options.loadAll || this.options.showIndex ==i) {
                if(data[i].url) {
                    //添加iframe
                    var iframe = $(this.template.iframe.format(data[i].id,i,height,data[i].url,data[i].url));
                    this.$element.find("#content-tabs").append(iframe);
                } else{
                    console.error("id=" + data[i].id + "的iframe页未指定url");
                }
            }
        }
        //console.log("this++",this);
        //console.log("thisdafult++",BaseIframe.prototype.default);
        if(data.length > 1){
            this.$element.find("#content-tabs iframe").eq(this.options.showIndex).css("display","inline");
            this.$element.find('#page-tabs a').eq(this.options.showIndex).addClass('active');
        }else{
            this.$element.find("#content-tabs iframe").eq(0).css("display","inline");
            this.$element.find('#page-tabs a').eq(0).addClass('active');
        }
        //绑定事件
BaseIframe.prototype.eventses();
        //$("#content-tabs iframe").css("height",height);
        //console.log(thisElement.attr('id'));
        //console.log(thisElement.html());
}
    
    /**点击事件*/BaseIframe.prototype.eventses = function() {
        //console.log("thisElement",thisElement);
        thisElement.find("#page-tabs a i").each(function(){
            $(this).click(function(){
                var id = $(this).data('id');
                //console.log('ad0',id);
BaseIframe.prototype.remove(id);
            });
        });
        thisElement.find("#page-tabs a").click(function(){
            //console.log("点击a: ",this);
            var dataUrl = $(this).data('id');
            var menuName = $(this).text();
            var name = $(this).attr('name');
            var dataIndex = $(this).data('index');;
            BaseIframe.prototype.openIframe(dataUrl,name,dataIndex);
        });
        
    }
    
    //新增一个Iframe页
    BaseIframe.prototype.addIframe = function(obj) {
        var nav_a = $(this.template.nav_a.format(obj.url,$('#page-tabs a').length,obj.id ,obj.text));
        //如果可关闭,插入关闭图标,并绑定关闭事件
        if(obj.closeable) {
            var a_close = $(this.template.a_close.format(obj.id));

            nav_a.append("&nbsp;");
            nav_a.append(a_close);
        }
        
        thisElement.find("#page-tabs").append(nav_a);
      
        BaseIframe.prototype.eventses();
    }
    
    /**隐藏其他的,显示当前*/BaseIframe.prototype.hidden_a = function(obj){
        thisElement.find('#page-tabs a').each(function(){
            $(this).removeClass('active');
        });
        thisElement.find('#content-tabs iframe').each(function(){
            $(this).css("display","none");
        });
        thisElement.find("iframe[name='"+obj+"']").css("display","inline");
        thisElement.find("a[name='"+obj+"']").addClass('active');
        //console.log("height",height);
        //thisElement.find("#content-tabs iframe").css("height",height);
}

    //根据id获取活动也标签名
    BaseIframe.prototype.find=function(tabId) {
        return this.$element.find(".nav-tabs li a[href='https://tool.4xseo.com/article/22372.html" + tabId + "']").text();
    }
    
    //删除活动页
    BaseIframe.prototype.remove=function(obj) {
        thisElement.find("#content-tabs iframe[name='"+obj+"']").remove();
        thisElement.find("#page-tabs a[name='"+obj+"']").remove();
        thisElement.find('#page-tabs a').eq(0).addClass('active');
        thisElement.find("#content-tabs iframe").eq(0).css("display","inline");
         if(thisElement.find('#page-tabs a').length > 0){
             var a = thisElement.find('#page-tabs a').eq(0);//找到第一个a标签取出数据
             this.openIframe(a.data('id'),a.attr('name'),a.data('index'));
         }
    }

    //根据id设置活动iframe页
    BaseIframe.prototype.showIframe=function(tabId) {
        var a = thisElement.find("#page-tabs a[name='" + tabId + "']");//找到a标签
        //console.log("a标签",a);
        var dataUrl = a.data('id');
        var dataIndex = a.data('index');;
        BaseIframe.prototype.openIframe(dataUrl,tabId,dataIndex);
    }

    //获取当前活动iframe页的ID
    BaseIframe.prototype.getCurrentIframeId=function() {
        var id=thisElement.find("#page-tabs .active a").attr("name");
        console.log('id',id);
        returnid;
    }

    String.prototype.format = function() {
        if (arguments.length == 0) return this;
        for (var s = this, i = 0; i < arguments.length; i++)
            s = s.replace(new RegExp("\{" + i + "\}", "g"), arguments[i]);
        returns;
    };
})(jQuery, window, document)
View Code

参数说明:

bootstrap添加iframe页第7张

方法说明:

bootstrap添加iframe页第8张

免责声明:文章转载自《bootstrap添加iframe页》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇权限认证机制Linux shadow文件中密码的加密方式下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

(二)文档请求不同源之window.name跨域

一、基本原理 window.name不是一个普通的全局变量,而是当前窗口的名字。这里要注意的是每个iframe都有包裹它的window,而这个window 是top window的子窗口,而它自然也有window.name的属性,window.name在不同的页面(甚至不同域名)加载后依旧存在(如果没修改则值不会变化),并且可以支持非常长的name值(2M...

C#上传视频等大文件

最近遇见一个需要上传超大大文件的需求,调研了七牛和腾讯云的切片分段上传功能,因此在此整理前端大文件上传相关功能的实现。 在某些业务中,大文件上传是一个比较重要的交互场景,如上传入库比较大的Excel表格数据、上传影音文件等。如果文件体积比较大,或者网络条件不好时,上传的时间会比较长(要传输更多的报文,丢包重传的概率也更大),用户不能刷新页面,只能耐心等待请...

未分类[selenium]-元素定位不到的原因及解决办法

摘自-宋现锋《测试开发工程师丛书》,如有版权问题请及时联系本人,谢谢. 在我们编写自动化测试用例的过程中,经常会遇到元素定位不到的现象,有的时候我们用 Selenium IDE 检查的时候也能在 Firebug 中看到,可是运行代码的时候,总是提示元素找不到。经过我以往和经验和大家在网上的讨论,我总结了以下几种情况: (1) 定位属性值是动态变化的情况 现...

apex:iframe 调用其他visaulforce page

<apex:page > <apex:iframe src="http://t.zoukankan.com/apex/API_Extjs_app" scrolling="true" /> </apex:page> 可扩展成动态调用...

python selenium 基本常用操作

 最近学习UI自动化,把一些常用的方法总结一下,方便自己以后查阅需要。因本人水平有限,有不对之处多多包涵!欢迎指正! 一、xpath模糊匹配定位元素 武林至尊,宝刀屠龙刀(xpath),倚天不出(css),谁与争锋  学会了xpath,妈妈再也不用担心我定位不到元素啦 ^_^ # coding:utf-8 import time from seleniu...

兼容各浏览器的iframe方法

方法一:(推荐1) <iframe src="http://t.zoukankan.com/Home/CreateGroup?classID=@ViewBag.ClassID" scrolling="no" frameborder="0" width="82%"></iframe><script type="text/java...