Click here to Skip to main content
15,887,214 members
Articles / Web Development / ASP.NET

Hosting IFRAMEs using the JQuery UI Tabs plug-in - Part 1

Rate me:
Please Sign up or sign in to vote.
4.89/5 (20 votes)
23 Dec 2009CPOL9 min read 95.2K   1.9K   73  
Using JQuery UI Tabs to host web pages via IFRAMEs.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HomeSite._Default" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Home Site</title>
    <link href="css/jquery-ui-1.7.2.custom.css" type="text/css" rel="stylesheet" />
    <link href="css/Main.css"type="text/css" rel="stylesheet" />
    <script src="JavaScript/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="Javascript/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>
    <script src="Javascript/jquery.hijack.min.js" type="text/javascript"></script>
    <script type="text/javascript">

        // JQuery scripting
        $(document).ready(function()
        {
            var browser = navigator.appName;
            var heightAdjust = 23;
            var widthAdjust = 7;
            
            // Make height and width offset adjusts for non-IE browsers 
            if (browser != "Microsoft Internet Explorer")
            {
                heightAdjust = 18;
                widthAdjust = 9;
            }
            
            // Show the panelList UL element so we can setup the tabs
            // Please note this approach eliminates Flash of Unstyled Content (FOUC)
            $('#panelList').show();
            
            // Setup the jQuery UI tabs
	        $('#tabPage').tabs({
                cache: true, // This ensures selecting a tab does not refresh the page
                load: function(event, ui)
                {
                    // Keep links, form submissions, etc. contained within the tab
                    $(ui.panel).hijack();
                    
                    // Adjust the IFRAME size correctly in the browser window
                    $('.contentsIframe').width((ViewPortWidth() - widthAdjust));
                    $('.contentsIframe').height((ViewPortHeight() - $('.menuRow').height() - $('.tabs').height() - heightAdjust));
                }
            });
            
            // Toggle arrow button image and hide/show menu area
            $('#collapseArrow').click(function()
            {
            
                if ($(this).hasClass('ui-icon-circle-triangle-s'))
                {
                    $(this).removeClass('ui-icon-circle-triangle-s');
                    $(this).addClass('ui-icon-circle-triangle-n');
                    $('#menuDiv').show();
                }
                else
                {
                    $(this).removeClass('ui-icon-circle-triangle-n');
                    $(this).addClass('ui-icon-circle-triangle-s');
                    $('#menuDiv').hide();
                }
                
                // Adjust the IFRAME size correctly in the browser window
                $('.contentsIframe').width((ViewPortWidth() - widthAdjust));
                $('.contentsIframe').height((ViewPortHeight() - $('.menuRow').height() - $('.tabs').height() - heightAdjust));
            });
            
            // Adjust tab header width and visible iframe window height and width after the window is resized
            $(window).resize(function(){
                $('.contentsIframe').width((ViewPortWidth() - widthAdjust));
                $('.contentsIframe').height((ViewPortHeight() - $('.menuRow').height() - $('.tabs').height() - heightAdjust));
                $('.ui-widget-header').width(ViewPortWidth() - widthAdjust);
            });
            
            // Adjust tab header height and width according to the IE client viewing area
            $('.ui-widget-header').width(ViewPortWidth() - widthAdjust);
            
            // Adjust the IFRAME height correctly in the browser window
            $('.contentsIframe').height((ViewPortHeight() - $('.menuRow').height() - $('.tabs').height() - heightAdjust));
        });
        
        // Returns width of viewable area in the browser
        function ViewPortWidth()
        {
            var width = 0;

            if ((document.documentElement) && (document.documentElement.clientWidth)) {
                width = document.documentElement.clientWidth;
            }
            else if ((document.body) && (document.body.clientWidth)) {
                width = document.body.clientWidth;
            }
            else if (window.innerWidth) {
                width = window.innerWidth;
            }

            return width;
        }

        // Returns height of viewable area in the browser
        function ViewPortHeight()
        {
            var height = 0;

            if (window.innerHeight) {
                height = window.innerHeight;
            }
            else if ((document.documentElement) && (document.documentElement.clientHeight)) {
                height = document.documentElement.clientHeight;
            }

            return height;
        }

    </script>
</head>
<body class="mainBody" style="margin:0">
    <form id="form1" runat="server">
        <asp:ScriptManager id="ScriptManager1" runat="server" />
        <div>
            <table id="mainTable" cellpadding="0" cellspacing="0">
                <tr class="menuRow">
                    <td align="left" valign="top">
                        <span id="collapseArrow" title="Show/Hide Header" class="menuSpan ui-icon ui-icon-circle-triangle-n"></span>
                        <div id="menuDiv" class="menuDiv">This is the header area.<br /><i>Please customize this area as you set fit; i.e. add a logo, menu options, links, etc.</i><br /><br /></div>
                    </td>
                </tr>
                <tr>
                    <td class="tabPageCell" colspan="2" valign="top" align="left">
                        <div id="tabPage" class="contents">
                            <ul id="panelList" class="tabs" runat="server" />
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer Intel Corporation
United States United States
I am an Automation Engineer specializing in application and web development/support.

Comments and Discussions