Javascript PostMessage to Parent from Child .. resize iframe according to jQueryUI tab height

Hi there,

I am stuck on a problem using postMessage to instruct a parent page to resize the iframe that holds the child page.

The child page has jqueryUI tabs on it and each tab can be drastically different in the height of the content ...

So, I set up some code on the select: function of the jQueryUI tab-set to get the height of the content of the tab.

But, my code works in Firefox but it does not work in Internet Explorer (sheesh!)

Here is a link to my sample parent page .. which works in FF but not in IE.

Link to my test page:  http://www.carcaraway.com/parent_page.html

From the child, I need to tell the parent to resize the iframe based on the size of the currently selected tab's content.

Does someone know of a better way to do this ... aka .. a way that works in FF and IE, etc?

Please help!

Thx Scott

ps;  In IE it resizes if the selected tab's content is BIGGER .. but if it is smaller ... I still get the same height value as the previously used tab....it does not change.

I am using $('body').outerHeight( true );  to get the height of the content ... but like I said ... does not work in all browsers...
srbarker8Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
remove the console.log

console.log
0
leakim971PluritechnicianCommented:
In developer mode, check what is the size sent to the parent :
wrong size value !
Why are you using jquery 1.3.2 ?
It's too old !!!
0
Michel PlungjanIT ExpertCommented:
1) change the console.log to

window.console && console.log

to make sure you do not get errors when the console is not open

2)

      xx = $('body').outerHeight( true );
      parent.postMessage(xx,'*');

does not work for IE proper.

The values I get when I click on tabs 2, 3, 2, 3 are

LOG: Tab number 1 - Tab Two - clicked
LOG: parent received message!:  610
LOG: Tab number 2 - Tab Three - clicked
LOG: parent received message!:  640
LOG: Tab number 1 - Tab Two - clicked
LOG: parent received message!:  670
LOG: Tab number 2 - Tab Three - clicked
LOG: parent received message!:  700
LOG: Tab number 1 - Tab Two - clicked
LOG: parent received message!:  730
LOG: Tab number 2 - Tab Three - clicked
LOG: parent received message!:  760
LOG: Tab number 1 - Tab Two - clicked
LOG: parent received message!:  790
LOG: Tab number 2 - Tab Three - clicked
LOG: parent received message!:  820
LOG: Tab number 1 - Tab Two - clicked
LOG: parent received message!:  850
LOG: Tab number 2 - Tab Three - clicked
LOG: parent received message!:  880
LOG: Tab number 1 - Tab Two - clicked
LOG: parent received message!:  910
LOG: Tab number 2 - Tab Three - clicked
LOG: parent received message!:  940

Open in new window


so my suggestion is to find the correct height.

3) IF you do not have another origin in the iFrame, then there is 0 reason to use postMessage just

parent.ifr.style.height = xxx+"px"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

leakim971PluritechnicianCommented:
replace : xx = $(body).outerHeight( true );
by : xx = $("hr").position().top - $("h3").position().top;

It will work :)
0
srbarker8Author Commented:
Thx - that works.

Are you are right about the old jquery.

But, I just tried to upgrade the jquery libs ... and it stopped working.

I am going to post it again with the new libs not working
0
Michel PlungjanIT ExpertCommented:
Be sure to use 1.1+ and not 2.0 which will not work in IE8
0
leakim971PluritechnicianCommented:
1.11 :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.