Solved

how to set the height of iframe to 100% of the content

Posted on 2011-09-11
7
349 Views
Last Modified: 2012-05-12
hi i am going to give the oportunity to developers to use my page as resource for the bible. so they will add this script on their page:

<script type="text/javascript">
    quartelcristao_idb = "29";
    quartelcristao_idl = "692";
    quartelcristao_width = "950px";
</script>
<script src="http://www.quartelcristao.com/js/biblia/style01.js"></script>

but i want the iframe height to be 100% of the content. but not always is happening, don't know why. i try this on the style01.js file:

function QuartelCristao_Biblia_Resize_iframe() {
    var height = window.innerWidth; //Firefox
    if (document.body.clientHeight) {
       height = document.body.clientHeight; //IE
    }
    document.getElementById("QuartelCristao_Biblia_iframe").style.height = parseInt(height - document.getElementById("QuartelCristao_Biblia_iframe").offsetTop - 8) + "px";
}

window.onresize = QuartelCristao_Biblia_Resize_iframe;
 
(
function () {
   var url = "http://www.quartelcristao.com/js/biblia/style01/Default.aspx?";
    var current_location = window.location.hostname;
    url += "?" + "idb=" + quartelcristao_idb + "&idl=" + quartelcristao_idl;
    document.write("<iframe id='QuartelCristao_Biblia_iframe' width='" + quartelcristao_width + "' height='100%' frameborder=0 onLoad='QuartelCristao_Biblia_Resize_iframe()' src='" + url + "'></iframe>");
})()

Open in new window

0
Comment
Question by:rafaelrgl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36520095
line 2, why innerWidth? var height = window.innerWidth; //Firefox

else check this : http://www.slackcoders.com/2008/03/10/iframe-dynamic-resizing-solved/
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 36521052
Firefox also understands document.body.clientWidth now
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 36524878
this was just an code that i get on the internet. so we don't need this one anymore innerwidth?

something is wrong with my code any guess? or any changes i should make?
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 1

Author Comment

by:rafaelrgl
ID: 36539614
pls, if you have time help me
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36539636
line 2, why innerWidth? var height = window.innerWidth; //Firefox

else check this : http://www.slackcoders.com/2008/03/10/iframe-dynamic-resizing-solved/
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 36539745
Sorry leakim971,

but i already delete this line and still same problem. and i also already read and did everything what this link shows? i think there is something wrong with that code on that page. did u test it before u gave this link or you just read solved on the link and did think it's solved?

sorry. but the problem still going on.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36539870
don't delete it

var height = window.innerWidth; //Firefox

I see innerWidth and height, logically it should be var height = window.innerHeight;
no? It was just a thought

https://developer.mozilla.org/fr/DOM/window.innerHeight
0

Featured Post

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to dynamically set the form action using jQuery.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question