We help IT Professionals succeed at work.

IFRAME resizing

mmc98dl1 asked
Last Modified: 2011-10-03
Hi all,

I have a small piece of JS to resize IFRAME's within the same domain so that the iframe doesnt scroll. The js is within the iframe.

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
                  //-- Frame Handling Script - Wax Interactive - May 2005
                  function resizeIframe() {
                  minFrameHeight = 250;
                  contentHeight = document.body.scrollHeight;
                  if (minFrameHeight > contentHeight) contentHeight = minFrameHeight;
                  this.parent.document.getElementById("contentFrame").style.height = contentHeight;
                  if (this.parent.document.getElementById("contentFrame").style.height)
                  this.parent.document.getElementById("contentFrame").scrolling = "no";
                  document.domain = "adage.com.au";
                  //-- End Frame Handling Script

<iframe name="contentFrame" id="contentFrame" src="http://jobs.adage.com.au/" style="border: 1px white solid;" width="100%" height="1000" frameborder="0" scrollbars="0">
            <p>Your browser needs to support I-FRAMES in order to view this area of the website.<br>
            Please download one of the following browsers:</p>
            <p><a href="http://www.microsoft.com/ie" target="_blank">Microsoft Internet Explorer</a><br>
                  <a href="http://www.mozilla.org/products/firefox/" target="_blank">Mozilla Firefox</a>

You can see this in action at http://www.adage.com.au/findajob.asp and it works just great.

I have now had some trouble in applying the same thing to a different site.
http://www.hireinsight.com.au/jobseeker.html - original code.
http://www.hireinsight.com.au/iframe.html - trial of the adage.com.au code on hireinsight.com.au
http://www.hireinsight.com.au/iframe2.html - trial of iframe on balnk page.

Can anyone see why this isnt working?
Watch Question

ZvonkoSystems architect
Top Expert 2006

It is not working because you try to set a foreign domain:
     document.domain = "adage.com.au";

That is not allowed.
Try setting this:
     document.domain = "hireinsight.com.au";

ZvonkoSystems architect
Top Expert 2006

Or in other words, cross domain access id forbidden.
So as soon as parent window and iĀ“frame are different internet domains you cannot read none of the attributes of the other domain.
All you can do is to set window.location or window.frames.iframeName.location
But you cannot even read the actual location.


>>It is not working because you try to set a foreign domain:
     document.domain = "adage.com.au";

Can you be more specific? In which example is this the case - as far as I am aware none of them use incorrect domains.

You will notice that we set adage.com.au on the adage.com.au iframe. On the hireinsight.com.au domain we set the hireinsight.com.au inside the iframe.

You will see that on http://www.adage.com.au/findajob.asp the code is all correct and that it works fine.

You will also see on http://www.hireinsight.com.au/jobseeker.html that the code is exactly the same and there is no difference apart from the domain.

My question is why does the adage.com.au work and hireinsight.com.au doesnt work???


>> cross domain access id forbidden.

I know that - the js is dynamically created in a ColdFusion page which reads the URL of the iframe domain. it then puts this into the js and (in the case3 of adage.com.au) it resizes because the domains are in line.

Why does the same thing not work on hireinsight.com.au?

Why does it not work on http://www.hireinsight.com.au/iframe2.html - a completely blank page with all the correct domain info???


Systems architect
Top Expert 2006
This one is on us!
(Get your first solution completely free - no credit card required)
ZvonkoSystems architect
Top Expert 2006

You are welcome.


Thanks - I couldnt see it, I knew there was a reason!!
ZvonkoSystems architect
Top Expert 2006


Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.