Sun 22 Oct 2006
While recently looking into Google Gadgets and pondering on the possibility of an open gadgets API that allowed you to place gadgets on your own site that were hosted elsewhere, I came up with a method that can be used for resizing IFrames where the page within the IFrame is hosted on a different domain.
A simple search for “resizing iframes” on Google returns 581,000 results, and the first one that I found gave a perfectly reasonable method for resizing iframes when all the content is stored on a single domain. Unfortunately due to the security restrictions in modern browsers, JavaScript in a page hosted on one domain cannot access a page hosted on an alternative domain, even if you really really want it to. But there is a way to allow communication.
So first, before I describe the solution I’ll mention a caveat – this solution relies on the page in the iframe doing something. This means you can’t have resizable iframes for just any content – either you have to have control of the content in the iframe or its owner has to make functionality available to you, but I think that’s a good security restriction. You have to trust the content you’re linking to if you’re going to implement this.
So – on to the solution. Put an iframe in your iframe. That’s it, that’s all you need to do. Come back next week for how to make Windows completely safe from viruses and Mac OS popular………..
What? You want more details? How about if I tell you to make the inner iframe link to something in the main window’s domain, does that help?

The diagram above aims to show you what I mean by this. You can also see this example in action. The main page in the example is served by the host mcknut.googlepages.com. It in turn has an iframe on it with some content from www.johnmckerrell.com. The three links inside the iframe try three different methods for resizing the iframe.
- The first link tries to simply access the parent window directly. This will not work on any modern browsers as it will be flagged as a security violation.
- The second link tries the best solution. There is a hidden iframe inside the main iframe. When you click on the second link iframe-resize1.html is loaded into the hidden iframe from mcknut.googlepages.com. iframe-resize1.html is passed a height value from the main iframe and then using JavaScript can access the main window, instructing it to resize the iframe. This is not flagged as a security risk because the domain of the page in the hidden iframe is the same as that of the main window.
- The third link tries another alternative which also works, but is slightly more cumbersome. This version loads the resizing page in the main iframe. The resizing page is served from the same domain as the main page and calls some JavaScript on the main page to resize the iframe. It then uses a callback mechanism to return the iframe to the original page. This is more cumbersome as it has to reload the content in the iframe, and would not be suitable for an iframe with dynamic content that might need resizing numerous times.
So, to wrap up, the second solution mentioned above is the ideal way, as it resizes the iframe without affecting the content within it. I see a definite security problem here if you have multiple iframes with content from multiple domains in, as you might find that any iframe would end up with the ability to impersonate any other iframe. I think this could be solved though by labelling the iframes using random strings and using these strings when communicating from iframe to main page. I’m also not entirely sure about the validity of the window.parent.parent.updateIFrame() line. As you can see from the diagram below, it looks like I’m being allowed to cross domains in my JavaScript which of course should not be possible. If this turns out to be a security violation that browsers are likely to fix, though, I think window.top.updateIFrame() would suffice in most circumstances, and should in theory be fine.

Please leave comments to let me know what you think of this solution. I’ve not been able to find it in use anywhere else but if you’ve seen something similar before then let me know. Also if you have any suggestions for improvements I’d be happy to hear them. I’ve been intending to have a go at a mechanism to allow two way communication between the iframe and the main page (currently you still wouldn’t be able to pass information into the iframe from the main page) but I haven’t had time to knock something up so if you do, let me know.
UPDATE: IFrame Example Code – I’ve now collected the files together into a zip file that you can download. You will need to change the domains (mcknut.googlepages.com and johnmckerrell.com) to your own domains though for it to work correctly.
UPDATE2: Basic iframes demo – I’ve stripped the example down to the three files you need and structured them into a hierarchy that should make it clearer which files go on which domain.
June 20th, 2007 at 2:54 pm
Anybody managed to get this working? John Ive copied ur instructions to the book but I keep getting permission denied errors. Is there anything I’m missing here or I should know that might be stopping mine from working?
Any help anyone can give me to get this working will be much appreciated.
Top Regards
June 20th, 2007 at 4:18 pm
As mentioned by email, so long as you make sure that the resizing iframe is hosted and loaded from the same domain as the main page, this should all work.
June 25th, 2007 at 10:23 am
Got it working! I moved the inner iFrame onto the same domain and everything is ok now. Thanks Alot John
C
June 25th, 2007 at 10:36 am
Glad you got it working Craig, and thanks for posting the followup
July 13th, 2007 at 3:00 pm
Greate job very helpfull for me and works fine. Thanks a lot.
August 11th, 2007 at 3:47 am
Here’s my scenario. Our clients have an iFrame on their web site that load a page on our domain. We need to resize the iframe each time the iFrame shows a different page.
The resolution for method 2 requires the hidden iFrame to point to a file on the client’s server. This is undesirable.
Would be great if there were a work-around to this. Is it possible for the iFrame to have a source of a about:blank or void or anything else?
August 13th, 2007 at 12:10 pm
@GpD – I’m not sure you’re going to be able to find any method that doesn’t involve your clients making changes on their side too.
If you simply want to remove the necessity for an extra file then you might want to try this alternative for iframe communication:
http://tagneto.blogspot.com/2006/06/cross-domain-frame-communication-with.html
December 14th, 2007 at 10:35 pm
Here’s an example of two-way cross-domain iframe communication using the Yahoo libraries
http://www.julienlecomte.net/blogfiles/cross-frame/
January 18th, 2008 at 5:51 am
hello i want source code for this iframe thanks
January 18th, 2008 at 10:48 am
@guarang – You should be able to get the source code from the example that I’ve linked to in the post, but you can also now download the code in a zip file here.
January 21st, 2008 at 10:56 am
Hello Dear
I have one iframe in main page and in that iframe i have src of my site and i want to resize height of iframe according to its content but i cant able to do that because of cross domain and give me a error message that “access denied” so pls help me for that….
January 30th, 2008 at 10:24 am
@Guarang – If you follow the instructions on this page, or use one of the other examples listed in the comments, you should be able to get around that problem. You have to have some control over both sites though for this to work.
February 20th, 2008 at 6:58 pm
I don’t believe this is still working for IE 7 or Firefox 2.0+. Can anyone confirm this?
February 21st, 2008 at 11:01 am
@Ben – I’ve just tried the example page in IE7 and Firefox 2.0 without issue, not sure why it’s not working for you.
February 22nd, 2008 at 5:52 pm
Hi, John,
This is a clever solution and I’ve been able to implement it without trouble. Thank you very much for providing it.
The only somewhat minor annoyance I’m finding is with Firefox 2 (Win and Mac). Because I’d like the iframe to automatically resize itself instead of having to click a link, I’ve added test2() to its page’s onload event. Everything functions correctly, but Firefox does two odd things:
First, I’ve determined that it fires onLoad() (in iframetest-resize1.html) twice whenever you refresh the top level page.
Second, it continues to try to load something – I can’t tell what – endlessly. (The “loading” icon in the top right of the browser never stops spinning.)
The above oddities seem related to the fact that an iframe is loading in an iframe, because if I comment out the line setting the iframe-in-an-iframe’s src, the endless loading issue does not happen.
Have you encountered this and/or have any ideas how to prevent it?
Thanks,
Joe
February 22nd, 2008 at 7:25 pm
@Joe – For the problem of the double onLoad events, you could check what the src of the iframe is before you set it (i.e. in test2). You’ll probably find that Firefox is remembering that the inner iframe contained iframetest-resize1.html so is loading it on its own, and then your code is also callign test2().
Alternatively, and probably better, would be to remove the iframe from the HTML and to instead create an iframe using JS DOM functions. I think this will get rid of your problem with the “loading” icon too.
February 24th, 2008 at 2:44 am
Hi, John,
I tried creating the iframe on-the-fly with JS, but that didn’t resolve the issue. I haven’t tried checking for the iframe source first, yet.
I stumbled upon an inexplicable solution, however: In my case, the page on which the resizeable iframe appears contains graphical navigation items with JS-controlled mouseover states. Mousing over one of these items stops the browser loading. I have no idea why this happens, but it’s my temporary work-around until I figure out something that makes sense to me.
Thanks,
Joe
March 11th, 2008 at 1:40 pm
Hi John,
I use your script, it’s very usefull to me, I have a web application where i have a Iframe calling another web applicattion, thanks to your script and use of a maste rpage can i fit the iframe with the content. i just need to put some code in the maste page, great solution buddy.
Thank,
Lucas
March 12th, 2008 at 9:44 pm
I’ve been wanting to use an iFrame for a particular site I’m working on (a sidebar with 200+ links). I’ve got my iFrame embedded well (using HTML and CSS), but I keep running into an issue whenever the link is clicked, the content loads into the frame, and not the ‘main’ page. what am I missing?
March 12th, 2008 at 11:22 pm
@Norcross – could it be that you need to add target=”_top” to the links in your iframe so that they load ing the “top” (i.e. the main) page?
March 17th, 2008 at 12:43 pm
WARNING: The dowload code is not identical with the example code. It is missing:
var height = Math.max( document.body.offsetHeight, document.body.scrollHeight );
March 18th, 2008 at 11:50 pm
Relates to John’s post from earlier… I just wondered whether you had had any further thoughts on resolving this ‘perpetual loading problem’ I’m encountering the same problem when I put the test2() function in the onload event.
Have tried trapping the src – nothing in it before I set it with test2()
Cheers,
Karl
March 19th, 2008 at 10:23 am
@Frank – Thanks for pointing that out, I’ve now fixed the download.
@Karl – I’ve just had a play with using an onload event and I also saw the same issue. I tried a few things and the only one that seemed to work was to put the call to test2() inside a timeout, this makes sure it occurs after the onload event has completed (and thus stops the spinner from perpetually spinning). A 100ms timeout is enough to fix the bug and won’t be noticeable to the user. Here’s the code that I used:
window.onload = function() {
setTimeout( function() {
test2();
}, 100 );
};
March 19th, 2008 at 10:48 am
Alternately, you can put test2() at the end of the document if you don’t mind adding a script tag to the html.
March 19th, 2008 at 1:00 pm
John,
Thanks for your quick response!
Frank,
Thanks for your comments… after posting last night I was playing around and figured that one out too, works like a charm.
Thanks to you both. Strangely and still getting scrollbars appearing, but I’ll dig in to the maths to figure out what’s going on.
March 19th, 2008 at 2:50 pm
Sorry to come back to this again,
But now I’m finding that the frame will dynamically enlarge fine, but once it’s enlarged it will not shrink again (for example from switching from a small content page to a large content page and back again). Any ideas?
March 19th, 2008 at 2:57 pm
An immediate follow-up to my last post – it seems that the following line doesn’t work for shrinking the page:
Math.max( document.body.offsetHeight, document.body.scrollHeight );
as scrollheight will report the larger (resized) iframe size. As math.max picks the largest number, the new smaller frame size doesn’t get passed to the resize function. Am just using the offsetHeight, which so far seems to work fine.
April 19th, 2008 at 12:11 am
brilliant work, john.
i’ve shared it here, and it received over 500 hits so far, in a few months. i rewrote your script, and prepared instructions for total beginners:
http://www.surveygizmo.com/forum/how-do-i-how-does-this-work-wtf/auto-fit-your-embedded-survey/page-1/post-4220/
THANKS
May 1st, 2008 at 4:35 pm
John
I find this information very useful. Thanks for putting this together.
I have a little different scenario and was working if your solution would work for it.
Heres our scenario: I have a website A that needs to be loaded into website B (on different domains). For this we have a javascript on website A domain and its included in website B using .
The javascript on website A is writing out a tag with iframe within it. and src of iframe has website A’s url.
With this website As url is getting loaded on website B. All this works fine but i am having trouble overriding styles used in page (website A) loaded within iframe and was wondering if there is a way to override the styles of page within iframe ?
If website A shares their styles sheet, can website B use it to customize it to their needs and have that modified stylesheet used by page loaded in iframe?
Thanks for your help
Kanth
May 5th, 2008 at 1:28 pm
@Kanth – I’m not sure but I don’t think you can override styles within an iframe from outside of it, you’d probably need JS to write a new stylesheet (which would also have cross domain problems) or some server-side process to manage the CSS files.
May 7th, 2008 at 4:46 pm
Thanks John! I am so glad you have this info posted here. This is truly the solution I was hoping to find in dealing with a cross server iframe presentation.
May 9th, 2008 at 5:11 pm
Thanks John for the reply
I found a workaround for overriding the styles within an iframe from outside of it.
Using the same example i have in my earlier post…
website A will have stylesheet and will be the default one and also since website A can share the stylesheet file…(css file)…website B has access to stylesheet file and if they want to make any changes to the styles they modify the css file distributed by website A and keep a customized file on their server…and since css file is public…when website B loads website A on their website within iFrame..they should be able to pass path of the customized css file to the javascript (residing on website A)..now website A can use this css path when passed from website B otherwise it uses default one..
i have tested this and was working fine..
June 16th, 2008 at 6:26 am
@Karl
Karl, please describe more in detail as you have solved a problem – I have faced with same, but offsetHeight does not work.
June 24th, 2008 at 12:42 pm
You a freekin Genius John!
Jethro Arenz
Cape Town, South Africa
July 9th, 2008 at 9:23 pm
Hello:
For those of you who are still having problems with Firefox never completing a load….
I put this in my hidden page and it worked!
if( typeof( height ) == ‘number’ ) {
window.top.updateIFrame( height );
window.top.stop();
}
July 16th, 2008 at 3:36 pm
Hello,
i am using IFRAME in my webapplication.The problem is the content that should be displayed inside this frame is from another domain.
For example, IFRAME is in “abc.com” and the content that is displayed inside this frame from “xyz.com”.
So the content is displaying but the IFRAME size matter.It is not adjusting the size with the content in another domain (ex : xyz.com).But the application in xyz.com is preconfigured we cannot modify except permissions to display. Anything that i can do is in “abc.com”.Iam using JavaScript.
I dont want scroll bars in frame.
For my application it is not possible to both app’s in same domain.
Can anybody provide the solution for the above problem will be much appreciated.
With the info provided in this page i came to know its a domain problem.Can’t be possible with IFRAME for displaying content from “xyz.com” ?
Thanks
August 8th, 2008 at 2:05 pm
Works perfectly, neat, simple. Thanks a lot !
August 26th, 2008 at 2:19 am
Thanks for the solution. Using the technique I wrote small snippet. In my case I have to load in iFrame third party content. I have multiple domain that point to same third part content so the path to the js file is dynamically created. That part works fine but when I try to load the iframe it does not work. This only happens in IE. Firefox works fine. Not sure why. any help.
August 26th, 2008 at 2:21 am
Oh and the third party has put the code snippet at the bottom of their page to load the hiddeniframe..
September 9th, 2008 at 1:01 am
Update: SOrry it took this while. The code actually works. I tweaked it well. The issue earlier was latency issue and I moved the code around without any issue.
September 18th, 2008 at 10:28 pm
Thank you very much for this solution. I have been searching for days. This works perfect.
October 1st, 2008 at 9:55 pm
This is an excellent solution. I am implementing this for a new project I am developing.
My only issue is I cannot seem to make it work within IE6. There is no JS error thrown, it just won’t work. Its as if IE6 completely skips over the script for some reason.
Still, I have tried your test page in IE6 and it works fine. Do you have any suggestions as to why this is not working for me.
Thanks in advance for your help
October 15th, 2008 at 6:32 pm
This is perfect. Worked so well. Thanks very much. Tested it on safari (mac and pc), firefox 3 (mac and pc), ie6, ie7 and chrome – all work great!
October 27th, 2008 at 4:22 am
Autofitting iFrame…
IntroductionDoes your iFrame step through multiple pages of varying heights? Or, does the height of the remote page change frequently?Do you find that the height of your iFrame is sometimes too short, cutting off the bottom of the remote page? Is y…
November 7th, 2008 at 10:52 pm
John,
Awesome work! been looking for a solution like this for a while now. However, I can only get it to work when “www” is included in the iframe ref for obvious reasons. For example iframe will resize if you are on “www.mydomain.com” but not when on “mydomain.com” Do you know of any way around this? Thank you in advance.
November 8th, 2008 at 9:08 pm
Ben,
This technique aims to get around the same domain problem between two sites on two domains. By adding a third domain, even if it’s just adding ‘www’ to the beginning, you’re exacerbating the problem.
I see that your site furnituredealer.net is also available on http://www.furnituredealer.net. I imagine you get some users hitting one domain and some hitting the other. One thing you could try would be to pass the HTTP_HOST value into the iframe so that the resizing iframe is definitely loaded from the same domain. My recommendation though would be that you modify your website so that it is only available on a single domain. This can be less confusing for your users, can improve your placing in search engines and makes site maintenance easier (such as this iframe problem).
If you need help with doing that contact me directly and I’ll try to offer some pointers.
November 12th, 2008 at 6:24 pm
John, thanks for your response. I should have explained better, sorry. our company http://www.furnituredealer.net runs over 30 websites for furniture companies. I was hoping to use your iframe resize code so my clients can self-service ad post by uploading a simple htm page with embedded google video. Please view this site for an example of how I have this setup:
http://www.olindes.com/adpage.aspx
We do not control our clients DNS so it would actually be lot of work to request they all move to a single domain. I ran my problem by some other developers in my office and they thought some ASP.NET code could solve the issue. What we came up with is below:
if (Request.Url.ToString().Substring(0, 10) != “http://www”)
{
Response.Redirect(“PUT YOUR URL HERE”);
}
I will let you know if this resolved the issue. Again, thank you for your response.
November 20th, 2008 at 9:14 am
Ben,
Could you either get the client to pass the host name through to your site using:
Request.ServerVariables(“HTTP_HOST”)
Or alternatively you could detect the host name by looking at the Referer header sent to the video URL?
Request.ServerVariables(“http_referer”)
John
December 10th, 2008 at 8:55 pm
I have an amalgamation of your script and another running that seems to cure my height issues. My last remaining task is now width. I’ve updated the script to pass a width variable to the inner iframe, but how do I get it to the top window? I managed to fake my scripting so far, but now I’m stuck!
any advice?
December 10th, 2008 at 9:15 pm
Nevermind… I got it
I added in the case statement wrong. after I fixed that, it was relatively easy.
this is an excellent script!
December 11th, 2008 at 10:59 pm
On second thought… I was able to get the isze to increase… how do I get it to decrease when going to the next page… I seem to be stuck at whatever the largest page was/is.
December 15th, 2008 at 3:01 pm
Thanks a lot, this worked beautifully.
January 5th, 2009 at 6:57 pm
still fighting with the width here. Seems to work great for height. but once your page width increases, I cant get it to shrink back down when accessign another page in the iframe. Any ideas?
January 6th, 2009 at 8:59 am
Is there an element within the iFrame that you can use to measure the width rather than measuring the width of the iFrame page? The problem is that once you’ve increased the width, that basically “is” the (minimum) width so you won’t be able to get it to shrink by detecting a property of document.body. I guess you must have some element that has a size smaller than the size of the iframe so if you use that you should have better results. You will of course need to add some pixels to the width of that element if you want padding.
March 5th, 2009 at 2:07 pm
Thank you for sharing. This worked perfectly for me and this is by far the simplest way to do cross-domain resizing.
March 6th, 2009 at 8:24 pm
Using the same words as Bethany, thanks a lot for sharing this. I have searched lots of links on internet, but this was the only way I could make it! God bless!
March 17th, 2009 at 5:54 pm
Hi John,
I have searched far and wide and this seems to be the closest to what I need but I need your advice on a slight variation. I have a page with an iframe in it. This iframe is loading a vacancies application which exists on another domain and as you click through the various option in this application the page changes height. I have added the ID into the iframe tag and also added the JS into the top of the page on the parent domain. However, I want this other domain to simply load into the iframe when the parent page loads rather than clicking an initial link in the iframe to then load the other domain.
I have got access to the other domain although the pages are created dynamically so I’m not sure where to add the necessary code to these pages and indeed what to add!
Any advice would be very welcome.
Is it as simple as adding:
function test2() {
var iframe = document.getElementById( ‘inneriframe’ );
var wrapper = document.getElementById( ‘wrapper’ );
var height = Math.max( document.body.offsetHeight, document.body.scrollHeight );
iframe.src = ‘http://mcknut.googlepages.com/iframetest-resize1.html?height=’+height;
}
function addContent( newcontent ) {
var wrapper = document.getElementById( ‘wrapper’ );
var newpara = document.createElement( ‘p’ );
wrapper.appendChild( newpara );
newpara.appendChild( document.createTextNode( newcontent ) );
}
:to the other domain’s page head and adding:
Many thanks,
Debbie
April 24th, 2009 at 11:00 pm
[...] on you being able to put code on your server, and being able to modify the source of the IFrame. Another solution I found relies only on modifying the source of the IFrame, but I found the hackiness [...]
July 9th, 2009 at 7:14 am
Anyone get this to work with safari or tested with safari? mine doesnt work with the latest version. its fine with everything else though
July 9th, 2009 at 7:59 am
@Peter – I’ve just tried the simple demo above in Safari 4 and it seems to work.
July 10th, 2009 at 5:03 pm
Hi John,
Thanx a ton to u r solution…
But i have some issue… I am getting the param and the height but getting the permission denied to get property Window.top.updateIFrame
Not sure of wat the problem is…
Wat i did was in X-domain i have the same content as mentioned in iframetest.html and in Y-domain i have iframetest-resize1.html content… When i try calling it from Y-domain i am getting the above said error…Help me out.
Thanx ina dvance for all ur valuable suggestion…
July 13th, 2009 at 10:18 am
I tried the way what you suggested, but no luck for me. I am not sure where it went wrong , Please help me.
Assume i have two domains A and B
In Domain A I kept the onLoad() and updateIframe () methods.
In domain B i kept the test2() method
While calling the method updateIframe() from onLoad() method its giving Permissio denied.
Here the method names which i used are in samples which one you provided
Please help me
Thanks
Sam
July 19th, 2009 at 11:57 am
Sam and Mani, I’m afraid there’s not much I can do other than suggest you go through your code again and make sure you’ve got the right files in the right places. If you can give a link to your code I may be able to offer more suggestions but without that all I can say is “Good Luck”!
July 21st, 2009 at 1:32 am
[...] Blog What I Made » Resizing IFrames Across Domains (tags: javascript iframe xss) [...]
September 22nd, 2009 at 3:37 pm
I’ve been reading and going through this for the last few hours, as I really want to make my blogger work within my indexhibit site.
Is it just me or are there a lack of instructions here?
There’s plenty about the theory but not much on what code to put where, I’m so lost. What do I do with the four different html files exactly?
October 16th, 2009 at 10:48 am
John,
Thank you for your beautiful solution! I have managed to embed my blogger blog into my personal web page and now I have even strip the alert, I didn’t notice the alert line before :$
You are great, man. Your solution awesome.
October 18th, 2009 at 7:09 pm
@Blas – glad you like it.
@Adam – I’ve put a cleaner version of the files into a zipfile I’ve mentioned on update 2 above, labelled “basic” (should really be “clean” but oh well). Hopefully this will be easier to use.
January 4th, 2010 at 3:35 pm
Thanks so much, been looking everywhere for this. Genius. Pure genius.
January 5th, 2010 at 11:26 am
Dear John,
For a while now i have been trying to implement your solution to my site. Unfortunately without any result. When I take a look at your example “see this example in action” non of the three links seem to alter the height of the frame either.
On my site the Iframe width and height simply remain 400 and 100 px as is written in innerframetest.html. Do I need to change these numbers?
Thanks for any help!
January 5th, 2010 at 4:19 pm
[...] Adam Fortuna explored some options using kind of a man-in-the-middle idea. This may have been inspired by a technique by John McKerrell. [...]
January 10th, 2010 at 4:11 pm
[...] Adam Fortuna explored some options using kind of a man-in-the-middle idea. This may have been inspired by a technique by John McKerrell. [...]
February 5th, 2010 at 4:13 am
Hi all,
Has anyone figured out the solution for bringing the iframe to a longer height to a shorter height?
Been working on this for days!
April 26th, 2010 at 2:42 pm
Absolute pure awesomeness!!!!!! With a few hours of brain bashing I was able to get this working. I have files on 2 servers on our intranet and this was the ONLY way to make the frames pointing to the other server work.
The coolest part is that I was able to integrate it into Joomla!!! I saved the files out as PHP, placed the script into my Joomla template after a few minor changes it works swimmingly. It also plays nice with the other iframe script I was already using. So the frames for the host server use one script and yours for the “remote” files. I can’t kiss your a** enough. Thank you much!
May 21st, 2010 at 7:22 pm
Works beautifully.
Only problem is decreasing the iFrame to a shorther height. Repeat Suf’s question: “Has anyone figured out the solution for bringing the iframe to a shorter height?
Would be just perfect if this problem was resolved.
May 21st, 2010 at 7:40 pm
@Rachel, @Suf – to get it to go to a shorter height you’ll need to put your iframe content within a
June 15th, 2010 at 5:24 pm
Works great other than decreasing the iFrame to a shorter height.
Could you show code for measuring height of div to find out what the height of the content is rather than the height of the element as suggested in your last post?
August 30th, 2010 at 5:24 pm
200$USD contract offer!——————-
Hi, I need to get some coding work done using the technique described here. I am willing to pay to get it working. Here is my problem:
This is working:
I have a main window, which sends a search query to the google search box form in an iframe. So the search results are displayed normally in the Google interface in the iframe (target=iframe). So all the code to obtain and display the proper results in Google is already working.
I now want to extract the Google search results found in the iframe, so in the main frame I tried to do:
function getContentFromIframe()
{
var myIFrame = document.getElementById(“iframeid”);
var test = myIFrame.contentWindow.document.getElementById(“nr_container”).innerHTML;
document.getElementById(“resultdiv”).innerHTML = test;
}
But access is denied, so I presume it has something to do with the Same Origin Policy, as it is cross-domain scripting.
I presume I need to retrieve the innerHTML of “nr_container”, which is the id of the div where results are injected in the Google search results page, and pass it to my main frame, but I need more access. I downloaded the example here, and it seems to be the solution I need, but I can’t figure out how to make it work properly. Please send me an e-mail if you are welling to help me figuring out how to set up the solution and make some tests.
I am welling to pay up to 200$USD to the first person that will resolve this problem.
I will pay using International Money Order.
Please help me!
January 6th, 2011 at 11:15 pm
[...] Problem #2: I didn’t want the iframe to have a scrollbar, so I needed some kind of auto-resizing script. However, the ASP application couldn’t execute correctly in the SharePoint web directory, so the SharePoint site and the old web app were on two separate domains. Therefore, I needed a cross-site iframe resizing solution. Fortunately, they exist. [...]
February 1st, 2011 at 3:08 pm
[...] not found) Posted by News On February 1st, 2011 / No Comments I’m using the code from John McKerrel to resize IFrames across domains (sample code is in a zip file there), there is an updated (bloated) version on CSS-Tricks: Cross [...]
May 13th, 2011 at 11:28 am
I have used your site and other- and found a mint solution! Check my post
http://stackoverflow.com/q/5908676/706363
May 13th, 2011 at 11:29 am
I have used your info and others and hve found a mint solution. Check my post on SO
http://stackoverflow.com/q/5908676/706363
May 27th, 2011 at 3:43 pm
Great! I made it automatically resize itself by putting this after the function resizethisFrame {
…
}
setInterval(“resizeThisFrame()”, 1000);
This resizes the frame every second, BUT as the script changes the iframe.src, it also reloads the page, so the back-button gets messy, and might slow down the browser.
It would be awesome if there was some way to make the frame resize itself as the contents change.
Anyone got any tips on that?
June 22nd, 2011 at 3:10 pm
[...] I found someone who does have a resolution. Full credit goes to John and his post here from [...]
July 14th, 2011 at 5:37 pm
Simply incredible. I’ve been looking around for this forever. Incidentally, regarding this:
“currently you still wouldn’t be able to pass information into the iframe from the main page”
I found this link: http://www.codeproject.com/KB/aspnet/IFrameParams.aspx
September 2nd, 2011 at 10:07 pm
Great solution and even greater that you provided such great documentation. Thank you.