473,413 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Resize IFRAME

Hi All,

Does anyone have any idea about how can we resize an IFRAME
dynamically according to its content from another domain? I want to
increase the height according to the page that is displayed on it.

Regards,
Jills
Jun 27 '08 #1
3 2067
On Jun 9, 2:28*pm, Jills wrote:
Does anyone have any idea about how can we resize an IFRAME
dynamically according to its content from another domain? I
want to increase the height according to the page that is
displayed on it.
The document object representation of a page from a different domain
will be inaccessible and so it will not be possible to determine the
display dimensions of that document. Without that information it will
not be possible to alter the height of the IFRAME to match the height
of that document.
Jun 27 '08 #2
Henry wrote:
On Jun 9, 2:28*pm, Jills wrote:
>Does anyone have any idea about how can we resize an IFRAME
dynamically according to its content from another domain? I
want to increase the height according to the page that is
displayed on it.

The document object representation of a page from a different domain
will be inaccessible and so it will not be possible to determine the
display dimensions of that document. Without that information it will
not be possible to alter the height of the IFRAME to match the height
of that document.
The original poster didn't mention how the iframe gets its new
content. When that instruction originates from the same domain as the
change of height, there is no problem:

<iframe id="ifr" height="100"></iframe>
<hr>
<input type="button" value="Google" onClick="
document.getElementById('ifr').src='http://www.google.com';
document.getElementById('ifr').height='200px';
">
<input type="button" value="Altavista" onClick="
document.getElementById('ifr').src='http://www.altavista.com';
document.getElementById('ifr').height='350px';
">

--
Bart
Jun 27 '08 #3
The html portion
------------------
<iframe id="myframe" src="externalpage.htm" scrolling="no"
marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0"
style="overflow:visible; width:100%; display:none"></iframe>

Now the javascript to use
-----------------------
<script type="text/javascript">

//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(navigat or.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+FFextr aHeight;
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>
-----------------------------

This will resize your iframe to the dimension of the source.

Enjoy


--------------------------
http://www.eecpindia.com
http://www.anchorfx.com
http://forex.eecpindia.com
*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex Blekhman | last post by:
Hello, I'm experienced Windows programmer, however, I'm quite novice in HTML technologies. Recently I was assigned a task to write small utility for internal use in our development team. I...
3
by: Guadala Harry | last post by:
Here's the functionality I'm after: I need for a page to display a photo. When users click on other links within the page, the photo changes. I'd like to swap out the photo without doing a...
2
by: wolfing1 | last post by:
Maybe this doesn't make any sense, but is it possible to dynamically resize an iframe to the height of its contained page? Something that works in Opera/Firefox/IE. I can resize it with a...
1
by: gary.comstock | last post by:
We have a non asp web page that contains a hyperlink which opens an iframe. The iframe is hidden until the hyperlink is selected then javascript toggles the visibility to 'visible'. Inside the...
1
by: traviscoop | last post by:
I have a modal dialog that opens up a url with my content in an iframe, I do this so the content can post back to itself, etc., I want the modal dialog to only be as big as it needs to be to show all...
2
by: mvmashraf | last post by:
How can I make an IFRAME resize itself when someone changes their resolution? I have a table in that i am loading that iframe, I did give the width of Iframe and the width of table as 100%, What...
0
by: Andy B | last post by:
I have an iframe on an aspx page with a poll inside of it. Somebody told me I should reduce the size of the iframe (make it skinnier) by just a small tad. I do know the poll inside the iframe is...
0
by: msoliver | last post by:
Issue: I want resize handlers within an iframe to be called when the main window changes size. Alternatively, I'd like to know how to propagate a resize event handled by the main window to iframe...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.