Solved

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

Posted on 2011-09-11
7
330 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
  • 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now