1 |
// load iframe and resize it |
2 |
// written by Dobrica Pavlinusic <dpavlin@rot13.org> |
3 |
// based on great hints from Robert Avilov |
4 |
|
5 |
var iframe_id_cache = Array(); |
6 |
|
7 |
function iframe_id(name) { |
8 |
if (! iframe_id_cache[name]) { |
9 |
iframe_id_cache[name] = self.document.getElementById(name); |
10 |
} |
11 |
return iframe_id_cache[name]; |
12 |
} |
13 |
|
14 |
|
15 |
function iframe_doc(name) { |
16 |
if (iframe_id(name).contentDocument) return iframe_id(name).contentDocument; |
17 |
if (iframe_id(name).contentWindow) { |
18 |
try { |
19 |
return iframe_id(name).contentWindow.document; |
20 |
} catch (e) {}; |
21 |
} |
22 |
if (iframe_id(name).document) return iframe_id(name).document; |
23 |
return null; |
24 |
} |
25 |
|
26 |
function iframe_height(name) { |
27 |
|
28 |
var doc = iframe_doc(name); |
29 |
|
30 |
if (doc.body) { |
31 |
var h = -1; |
32 |
var h1 = -1; |
33 |
|
34 |
if (doc.body.scrollHeight) { |
35 |
h1 = parseInt(doc.body.scrollHeight) || -1; |
36 |
//alert(name+" scrollHeight "+h1); |
37 |
if (h1 > h) h = h1; |
38 |
} |
39 |
if (doc.body.clientHeight) { |
40 |
h1 = parseInt(doc.body.clientHeight) || -1; |
41 |
//alert(name+" clientHeight "+h1); |
42 |
if (h1 > h) h = h1; |
43 |
} |
44 |
|
45 |
/* |
46 |
var elm = document.getElementById(name); |
47 |
if (elm) { |
48 |
elm.style.height = 'auto'; |
49 |
h1 = elm.offsetHeight; |
50 |
alert(name+" offsetHeight "+h1); |
51 |
if (h1 > h) h = h1; |
52 |
} |
53 |
*/ |
54 |
|
55 |
return h + 20; |
56 |
|
57 |
} |
58 |
return 50; |
59 |
} |
60 |
|
61 |
function iframe_resize(name) { |
62 |
|
63 |
var el=iframe_id(name); |
64 |
|
65 |
if (! el || ! el.src) return; |
66 |
|
67 |
el.style.height = String(iframe_height(name)+'px'); |
68 |
} |
69 |
|
70 |
function iframe_load(name,url) { |
71 |
|
72 |
if (! name || ! url) return false; |
73 |
|
74 |
var el=iframe_id(name); |
75 |
|
76 |
if (! el) alert("can't find element "+name); |
77 |
|
78 |
// is there src, and is src same? |
79 |
if (el.src && el.src.substr(el.src.length - url.length) == url) return false; |
80 |
|
81 |
el.style.height = '0px'; |
82 |
el.src = url; |
83 |
|
84 |
return false; |
85 |
} |
86 |
|