TinyPortal

Development => Support => Topic started by: Rocket on November 12, 2005, 01:06:53 AM

Title: Iframe Automatic resizing
Post by: Rocket on November 12, 2005, 01:06:53 AM
Anyone know how to automatically resize an IFRAME so that the window adjusts for the content?

Make sense?
Title: Re: Iframe Automatic resizing
Post by: iowamf on November 12, 2005, 02:51:29 AM
<iframe src="http://yoursite.com/example.html"  width="100%" height="800"> </iframe>

If I understand you correctly,  you can get part-way there with an article that contains the above HTML - but only the width "adjusts" for content - in the example above, the height is fixed.
Title: Re: Iframe Automatic resizing
Post by: Rocket on November 12, 2005, 04:02:17 AM
Exactly...

Some content may require a height of 500 where another may require 2000.  Maybe a page will need 2000 one day, but will need 2100 the next, such as in a list of users.  This assumes that we don't want any scroll bars so as to make the content seem integrated to the site.

Still make sense?
Title: Re: Iframe Automatic resizing
Post by: mjl on November 12, 2005, 11:22:01 AM
hello
iframe automatic in javascript.  ;)

exemple:

<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">

/***********************************************
* IFrame SSI script II- ÂÃ,© Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["myframe"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller

</script>
</head>

<body>
<iframe id="myframe" src="your page.html or .php" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" style="overflow:novisible; width:100%; display:none"></iframe>
</body>
</html>



Title: Re: Iframe Automatic resizing
Post by: gerrymo on November 12, 2005, 12:14:41 PM
Looks pretty cool. How do you call that into a page or block?
Title: Re: Iframe Automatic resizing
Post by: gerrymo on November 12, 2005, 01:14:45 PM
Here's the link to the site and details of how to set it up. Looks promising. Watch this space.

http://www.dynamicdrive.com/dynamicindex17/iframessi2.htm
Title: Re: Iframe Automatic resizing
Post by: Rocket on November 24, 2005, 03:13:05 AM
This works like a champ!ÂÃ,  There were a couple of extra characters in the original post.. I took those out.ÂÃ,  This is the code I use to call pages to the center of my site and resize them automatically.

Create a new article> paste the entire code into the article>ÂÃ,  modify the link at the bottom>ÂÃ,  THAT'S IT!

<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">

/***********************************************
* IFrame SSI script II- ÂÃ,© Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["myframe"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller

</script>
</head>

<body>
<iframe id="myframe" src="/yourfile/myfile.html or .php" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" style="overflow:novisible; width:100%; display:none"></iframe>
</body>
</html>


Thanks for posting this! mjl!

to see it in action go here --->ÂÃ,  http://www.xpertwarriors.org
Title: Re: Iframe Automatic resizing
Post by: Leviathan on November 24, 2005, 03:49:54 PM
Thanx Rocket and MJL, that works wonderfull!

/me is very happy
Title: Re: Iframe Automatic resizing
Post by: snork13 on November 24, 2005, 07:26:24 PM
this is great, i run my coppermine gallery in an iframe within the forum.../forum/index.php?action=gallery ;) and it looks even better now....thanks for sharing...

-snork
Title: Re: Iframe Automatic resizing
Post by: iowamf on November 24, 2005, 07:59:20 PM
Is there a limitation that all content pulled in needs to physically reside on your own website?
Title: Re: Iframe Automatic resizing
Post by: IchBin on November 25, 2005, 06:18:28 AM
No, you can actually make a php include and include it from another site AFAIK.
Title: Re: Iframe Automatic resizing
Post by: Sakuragi on November 25, 2005, 03:03:14 PM
does not work for me 
and i can't edit the article :(

[attachment deleted by admin]
Title: Re: Iframe Automatic resizing
Post by: IchBin on November 25, 2005, 04:57:46 PM
Turn off the editor in your TPAdmin panel and try to create your article then.
Title: Re: Iframe Automatic resizing
Post by: Maya on November 25, 2005, 06:06:48 PM
I was playing with this code yesterday, and I couldn't get it to work either, (even tried running it through a static page), and nada.

I tried it as an article with the editor toggle on and off, and both times got the same thing..

I have np getting the simple iframe code to work, but this one is kind of wonky, and the auto resize is pretty nifty ..
Title: Re: Iframe Automatic resizing
Post by: Sakuragi on November 26, 2005, 12:05:36 AM
thanks!
Title: Re: Iframe Automatic resizing
Post by: sc2sick on January 13, 2006, 12:25:02 AM
hmm... i'm having trouble getting this to work, where to i place the code?  the first code worked, but i really would rather not scroll over... the autosize would be nice.  i just don't know how much of the code i have to edit or where to place it.
Title: Re: Iframe Automatic resizing
Post by: Rocket on January 13, 2006, 02:04:20 AM
1)  Copy the entire code
2)  Paste the entire code in an article
3)  edit this bit at the bottom of the script.

<body>
<iframe id="myframe" src="/yourfile/myfile.html or .php" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" style="overflow:novisible; width:100%; display:none"></iframe>
</body>
</html>


Replace the "/yourfile/myfile.html or .php"  with the path to your file or folder.  For example if your gallery is in the folder "gallery"  your path would be - "/gallery/index.php"

Nothing else needs to be modifiied.  Save the article.

Go to Menu Manager and create a link to the article.
Title: Re: Iframe Automatic resizing
Post by: sc2sick on January 13, 2006, 02:42:08 AM
once i create a menu, how do i navigate to it?
Title: Re: Iframe Automatic resizing
Post by: sc2sick on January 13, 2006, 03:15:49 AM
i feel tarded....  i'm usually pretty decent @ this kind of stuff.
Title: Re: Iframe Automatic resizing
Post by: Rocket on January 13, 2006, 10:20:07 PM
mmmmkkk, You should have a block called content that is installed by default with TP (I think).

When you open TP admin, you will see a link called Menu Manager.  Once inside, type the name for the link, "Gallery" is good :)  and then select Article from the bullet list, choose the gallery article you made hit save and you are done!  Click the link. 

Your gallery will open in the center of your site.

I hope that answers your question.
Title: Re: Iframe Automatic resizing
Post by: aptd on April 05, 2006, 09:20:20 PM
I hate to bring up old topics...but I just can't get this to work!

I could really use some help, my brain is fried. :uglystupid2:

Anyway..

I have set up my article

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.dsull.com%2Ftp%2Farticle.jpg&hash=094c7e51afd458ec2abcf0a5ea100247ebee1bdc)

I have set up my Menu Item

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.dsull.com%2Ftp%2Fmenuitem.jpg&hash=9b7b145271cc7691d18ea937f307757cb603cb74)

and nothing.  Thing isn't showing up.  Though as you can see.  It shows up in the WYSIWYG article editor.

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.dsull.com%2Ftp%2Fnothing.jpg&hash=a6fd72910aec367e6700b5cb1097760e163fb62c)


Any help would be GREATLY appreciated!

_D
Title: Re: Iframe Automatic resizing
Post by: IchBin on April 05, 2006, 10:36:18 PM
Did you activate the article?
Title: Re: Iframe Automatic resizing
Post by: aptd on April 05, 2006, 11:11:28 PM
Yea...the green button right?
Title: Re: Iframe Automatic resizing
Post by: stigmartyr on April 05, 2006, 11:13:59 PM
What is the <iframe> code you are using.. the whole string.. can you paste it?

It looks like you have some kind of script embedded in a page that is not the same size as the frame is told to be.
Title: Re: Iframe Automatic resizing
Post by: aptd on April 05, 2006, 11:49:27 PM
I started with this when I made the article...

<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">

/***********************************************
* IFrame SSI script II- ÂÃ,© Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["myframe"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller

</script>
</head>

<body>
<iframe id="myframe" src="csserverpage.html" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" style="overflow:novisible; width:100%; display:none"></iframe>
</body>
</html>


And when I go back to the article..and click on the <> HTML button on the right there..it shows in green.

<IFRAME id=myframe style="DISPLAY: none; WIDTH: 100%" marginWidth=0 marginHeight=0 src="csserverpage.html" frameBorder=0 scrolling=no></IFRAME>
Title: Re: Iframe Automatic resizing
Post by: stigmartyr on April 06, 2006, 12:03:29 AM
I see ur using some sorta of auto generated iframe thingy.. IDK what its intended to produce... looks very bloated.


I suggest you try this modified iframe to open the csserverpage.html page, instead:


<iframe name="mainFrame" id="mainFrame" src="csserverpage.html" scrolling="no" align="center" frameborder="0" width="enter number in pixels here" height="enter number in pixels here"></iframe>



You will want to play with the height and width until it fits what you want it to look like.  Just start with 300 on each and go from there. ;)

The ginormous code you pasted for only opening a single iframe seems lag-tastic.

Let me know if it helps you!
Title: Re: Iframe Automatic resizing
Post by: aptd on April 06, 2006, 12:07:21 AM
I guess the "bloated" code, was that it would be dynamic to the stuff being loaded, instead of having to set the dimensions manually.  But I will try your way in a second here.
Title: Re: Iframe Automatic resizing
Post by: stigmartyr on April 06, 2006, 12:15:06 AM
ohhh.. so ur saying that it would auto-resize when the person views your content?  If the content window is going to expand and shrink you will want to provide static space for it anyways, IMHO.


In designing web-sites I try to keep the page from jumping around too much.  It irritates people.  You could start out with a fixed size canvas (black background or other) and set it to accomodate the largest sized page that will be opened inside. 

If you set scrolling to: scrolling="yes" or "auto" you can get scroll bars as well to scroll through stuff.
Title: Re: Iframe Automatic resizing
Post by: aptd on April 06, 2006, 12:17:08 AM
Ok, I guess the thing im trying to put in might not work like this.  But I cant figure out how to do it.

Suppose maybe teh HTML file needs to be changed.

What I am trying to put this stuff in this center there when I click on "Servers" under the content menu.  
http://dsull.com/smf/csserverpage.html

but you see, using the script, you gave me, I even put a height of 800 and a width of 400 and still end up with just part of the stuff.

As you can see here:

http://dsull.com/smf/index.php

I'mma do a search real quick to see how somebody else put it in.  I know I found some stuff where they put the information into blocks and put them on the left or right.  But i just want it as a seperate section under "servers".

_D
Title: Re: Iframe Automatic resizing
Post by: stigmartyr on April 06, 2006, 12:37:50 AM
The reason only PART of the csserverpage.html is showing is because the html page itself must be edited as well.

It is probably set to ALIGN="left" or "right" or something...


Make sure that it is aligned to CENTER and at the VERY top of the page.  It should then do its own job of auto-aligning itself in the iframe.
Title: Re: Iframe Automatic resizing
Post by: aptd on April 06, 2006, 12:42:13 AM
This is the only thing in the HTML

<!-- ServerSpy.Net Flashy Monitor #ID 209757 | START -->
<script language="JavaScript" type="text/JavaScript" src="http://share1.serverspy.net/bin/smonV2loader.mpl?mid=209757"></script>
<!-- ServerSpy.Net Flashy Monitor #ID 209757 | END -->



Guess I should have just made it an actual HTML page.  But it showed up in the WYSIWYG editor of the articles.

_D
Title: Re: Iframe Automatic resizing
Post by: stigmartyr on April 06, 2006, 12:58:32 AM
That script looks fine.  Do this:  we want to turn csserver.html into its own webpage.  So copy that script to notepad then delete the html.


Make a new page with the same exact name.  Then, insert a table with no borders so its invisible.  Click inside, make it center aligned.  Then type: XXX in it.


Go to HTML view, find the 'XXX' highlight it and 'replace' it with the copied script in your note pad.  Save it to your fourms root folder and then you can start playing with it.
Title: Re: Iframe Automatic resizing
Post by: aptd on April 06, 2006, 01:19:01 AM
Ok well, in the article editor WYSIWYG viewer, you can see more of the whole thing...the whole top portion..., but you cant see the rest.

As far as th epublic viewing it, still no joy.  Doesn't work.

I changed the HTML to this.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<table width="200" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center"><script language="JavaScript" type="text/JavaScript" src="http://share1.serverspy.net/bin/smonV2loader.mpl?mid=209757"></script></td>
  </tr>
</table>
</body>
</html>


Going to try it non-dynamically real quick.

_D
Title: Re: Iframe Automatic resizing
Post by: Rocket on April 06, 2006, 01:26:06 AM
The script you refer to as "lag-tastic" is actually a very useful and fast script.  Contrary to the way it was explained, the script will adjust for content.  This is useful for a list of users for example that changes over time.  You would not have to go back and adjust the sizing, neither would you have scroll bars.

I have used this successfully on about 3 TP/SMF sites now it works beautifully.  I would venture to say that it is FAN-tastic... :)
Title: Re: Iframe Automatic resizing
Post by: Rocket on April 06, 2006, 01:34:43 AM
aptd... this is your problem..

Turn off WYSIWYG, THEN paste your code in your article.

Sorry, didn't see it the first time.
Title: Re: Iframe Automatic resizing
Post by: aptd on April 06, 2006, 01:37:40 AM
Yes Rocket, I agree...sorry for jacking the thread, I didn;t know that the content I was trying to load was the problem instead of the script you rposted.  I love dynamc stuff, believe me, i'm a major flash junkie...but sorry for jacking the thread.

Anyways...I ended up just using the stand iframe call, with a tabled HTML file.  Changed the background color of that HTML to the background color of the forum and it works now.

Thanks a bunch stigmartyr.

http://www.dsull.com/smf/index.php

If you click on servers...then there you go.

Now I know how to put in all that stuff thanks to you both of you guys.  And I can size it myself or just make it dynamic.  

Hope this actually help ssomeone else.

_D
Title: Re: Iframe Automatic resizing
Post by: aptd on April 06, 2006, 01:38:40 AM
Quote from: Rocket on April 06, 2006, 01:34:43 AM
aptd... this is your problem..

Turn off WYSIWYG, THEN paste your code in your article.

Sorry, didn't see it the first time.

I will try this as well. Ill make it server test 2..

heh

Thanks

_D
Title: Re: Iframe Automatic resizing
Post by: aptd on April 06, 2006, 01:43:44 AM
WOW  ;D


Both of your guy's suggestions and solutions work!

Bravo!


Although the latter was quite a bit easier...

Thanks to both of you!

_D
Title: Re: Iframe Automatic resizing
Post by: Rocket on April 06, 2006, 02:20:11 AM
cool, glad you found something that works for you.
Title: Re: Iframe Automatic resizing
Post by: stigmartyr on April 06, 2006, 03:53:58 AM
Awesome.  Hey Rocket, I didnt have time to look at the site while I was working, but I am generally wary of obvious auto-gens.  It sounds like by ur description that it would be useful if it doesnt cause the page to jerk around as you navigate the frame.  Ill have to look into it more, thanks.