jquery ui tabs iframe 高度 寬度自適應
1
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
2
<%@ taglib prefix="s" uri="/struts-tags" %>
3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml">
5
<head>
6
<title>temp_title</title>
7
<%@ include file="/ui/common.jsp"%>
8
<%@ include file="/ui/components/jquery-ui/jquery-uiHead.jsp"%>
9
<script type="text/javascript">
10
$(document).ready(function(){
11
12
var browser = navigator.appName;
13
var heightAdjust = 23;
14
var widthAdjust = 7+20;
15
16
// Make height and width offset adjusts for non-IE browsers
17
if (browser != "Microsoft Internet Explorer")
18
{
19
heightAdjust = 18;
20
widthAdjust = 9+20;
21
}
22
23
$("#tabs").tabs({
24
cache: true, // This ensures selecting a tab does not refresh the page
25
load: function(event, ui)
26
{
27
// Keep links, form submissions, etc. contained within the tab
28
//$(ui.panel).hijack();
29
30
// Adjust the IFRAME size correctly in the browser window
31
$('.contentsIframe').width((ViewPortWidth() - widthAdjust));
32
$('.contentsIframe').height((ViewPortHeight() - $('#tabs_ul').height() - heightAdjust));
33
}
34
});
35
36
$("#tabs_ul li").click(function(){
37
var flag = false;
38
var tabId = $(this).attr("id");
39
var selectedItems = $("#tabs_ul li.selected");
40
if(selectedItems.length > 0){
41
var selectedItemId = selectedItems[0].id;
42
if(tabId != selectedItemId){ // 尚未選中
43
flag = true;
44
}
45
} else {
46
flag = true;
47
}
48
49
50
if(flag){
51
$(this).addClass("hover");
52
$(this).siblings().removeClass("hover");
53
54
var url = "";
55
if(tabId == "grant_menu"){
56
url = temp_ur1l;
57
} else if(tabId == "grant_business"){
58
url = temp_ur12;
59
} else if(tabId == "grant_resource"){
60
url = temp_ur13;
61
}else{
62
return;
63
}
64
$("#grant_iframe").attr("src", url);
65
}
66
});
67
$("#tabs_ul li")[0].click();
68
69
// Adjust tab header width and visible iframe window height and width after the window is resized
70
$(window).resize(function(){
71
$('#grant_iframe').width((ViewPortWidth() - widthAdjust));
72
$('#grant_iframe').height((ViewPortHeight() - $('#tabs_ul').height() - heightAdjust));
73
});
74
75
// Adjust the IFRAME height correctly in the browser window
76
$('#grant_iframe').height((ViewPortHeight() - $('#tabs_ul').height() - heightAdjust));
77
78
});
79
80
// Returns width of viewable area in the browser
81
function ViewPortWidth()
82
{
83
var width = 0;
84
85
if ((document.documentElement) && (document.documentElement.clientWidth)) {
86
width = document.documentElement.clientWidth;
87
}
88
else if ((document.body) && (document.body.clientWidth)) {
89
width = document.body.clientWidth;
90
}
91
else if (window.innerWidth) {
92
width = window.innerWidth;
93
}
94
95
return width;
96
}
97
98
// Returns height of viewable area in the browser
99
function ViewPortHeight()
100
{
101
var height = 0;
102
103
if (window.innerHeight) {
104
height = window.innerHeight;
105
}
106
else if ((document.documentElement) && (document.documentElement.clientHeight)) {
107
height = document.documentElement.clientHeight;
108
}
109
110
return height;
111
}
112
113
</script>
114
</head>
115
<body style="margin:0; overflow:hidden;">
116
<div id="tabs">
117
<ul id="tabs_ul">
118
<li id="grant_menu"><a href="#tabs-grant">時間設置</a></li>
119
<li id="grant_business"><a href="#tabs-grant">崗位參數</a></li>
120
<li id="grant_resource"><a href="#tabs-grant">項目參數</a></li>
121
</ul>
122
<div id="tabs-grant" >
123
<iframe id="grant_iframe" src="" frameborder="0" style="height:100%; width:100%; marginwidth:0; marginheight:0; scrolling:auto" ></iframe>
124
</div>
125
</div>
126
</body>
127
</html>
128
129

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

1、引用jquery-ui
2、設置body樣式margin:0; overflow:hidden;
3、設置iframe樣式 height:100%; width:100%; marginwidth:0; marginheight:0; scrolling:auto
4、設置窗體resize方法,以及高度的初始化值
posted on 2013-08-06 09:44 lanjh 閱讀(5596) 評論(3) 編輯 收藏 所屬分類: Java Web