?
Solved

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

Posted on 2014-02-06
7
Medium Priority
?
1,077 Views
Last Modified: 2014-02-08
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...
0
Comment
Question by:srbarker8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39841556
remove the console.log

console.log
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39841586
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
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 1000 total points
ID: 39841603
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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 1000 total points
ID: 39841609
replace : xx = $(body).outerHeight( true );
by : xx = $("hr").position().top - $("h3").position().top;

It will work :)
0
 

Author Closing Comment

by:srbarker8
ID: 39843431
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39843732
Be sure to use 1.1+ and not 2.0 which will not work in IE8
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39843994
1.11 :)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

771 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