Current location: Hot Scripts Forums » General Web Coding » JavaScript » [SOLVED] autoresize Iframe script works in explorer but not firefox


[SOLVED] autoresize Iframe script works in explorer but not firefox

Reply
  #1 (permalink)  
Old 06-25-08, 03:51 PM
rickymartin rickymartin is offline
New Member
 
Join Date: Jun 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] autoresize Iframe script works in explorer but not firefox

hi programmers!

My name is Brandon. I have been looking for someone on the web that can help me figure out a problem and stumbled across your site. After reading posts on your site, I found that you seemed to really understand the difference between explorer and firefox.I am a web designer that is in need of some help with this script which works in explorer but not firefox.

i have this awesome script which is so simple but works fantastic. It tells an iframe to load an html page but auto resizes to whatever hieght of the loaded html page.

the problem is that the script works in explorer only and not firefox. i read a big explanation of the difference between firefox and explorer but its way over my head im more of a designer rather than the backend although I do understand some of it. if i give you the code would any of you be able to figure out what needs to be changed in the script so it does work in firefox as well?

here is the script located right after the header:

JavaScript Code:
  1. <script language="JavaScript">
  2. <!--
  3. function calcHeight()
  4. {
  5. //find the height of the internal page
  6. var the_height=
  7. document.getElementById('content').contentWindow.
  8. document.body.scrollHeight;
  9.  
  10. //change the height of the iframe
  11. document.getElementById('content').height=
  12. the_height;
  13. }
  14. //-->
  15. </script>
then in the iframe the script is :

HTML Code:
<td height="194" colspan="4" valign="top" bgcolor="#FFFFFF"><iframe name="content" style="border:0px" width=923 onLoad="calcHeight();" src="home.htm" scrolling="NO" frameborder="0" height="0"> </iframe></td> 
(the only part below that communicates with the script above is ( onLoad="calcHeight();" )

I think it may be the onload part that firefox doesn’t understand.
thank you so much for helping me out.



Brandon

Last edited by TwoD; 06-25-08 at 07:33 PM. Reason: Added highlight wrappers. This is the most common misstake by new users...
Reply With Quote
  #2 (permalink)  
Old 06-25-08, 07:46 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
The script works fine for me in FF3, but you've got some HTML issues.

The iFrame has a name attribute set to "content", but since you're using document.getElementById, you should set an id-attribute (IE incorrectly gets the element anyway). Also make sure the script lines are held together and do not contain linebreaks, this might cause problems.
Linebreaks corrected:
JavaScript Code:
  1. <script type="text/javascript">
  2. <!--
  3. function calcHeight()
  4. {
  5. //find the height of the internal page
  6. var the_height=document.getElementById('content').contentWindow.document.body.scrollHeight;
  7.  
  8. //change the height of the iframe
  9. document.getElementById('content').height=the_height;
  10. }
  11. //-->
  12. </script>

Note that users might get problems with really large pages loaded this way, especially on low resolutions, as they can't scroll correctly.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #3 (permalink)  
Old 06-26-08, 04:32 PM
rickymartin rickymartin is offline
New Member
 
Join Date: Jun 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
hey there. i tried it. good and bad came out of it.

the good- it worked in firefox

the bad- it stopped working in explorer.

but.....

i did try something and it worked perfectly I used both. it seems that iframe name is what explorer understood and ID is what firefox understood. i really didnt think i could put both on the same line like that but it did!

code that worked for autoresize iframe for both fireworks and explorer : iframe name="content2" id="content2"

thank you very much for helping me. especially so quickly

Brandon
Reply With Quote
  #4 (permalink)  
Old 06-30-08, 01:50 PM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
I noticed you wrote "onLoad" in your code, with upper case L. It should all be in lowercase, like this: onload="..."
__________________
Jack Bauer makes Chuck Norris cry
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Works in Firefox not IE (popup) _matt JavaScript 1 01-28-07 06:48 AM
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 12:12 AM
Need an upload revision ebay script that works well. fooleo Job Offers & Assistance 0 12-07-03 07:21 PM
I made a new BLOG/Journal script! [ works on both MYSQL and FlatFiles! ] kailash General Advertisements 6 12-07-03 02:11 PM
Need a login script that works with paypal. dgames Script Requests 3 12-04-03 07:58 AM


All times are GMT -5. The time now is 11:39 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.