Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple responsive iframes on one page. #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sarahgoldman
Copy link

I closed my original pull request (#20) and am submitting this one because I fixed the navigating to new pages within frame issue I mentioned in the original pull request.

Now instead of passing the frame window's href in the postMessage and matching iframes based on src, I am passing the window name and matching iframe name attributes.

Note that this is not backwards compatible to existing markup in the sense that all responsive iframes need to have a unique name attribute. Existing markup won't break, it just won't match and resize.

If you wanted to support iframes without name attributes, I guess you could fall back to passing the href and then matching iframe srcs if an href is received instead of a name. But I didn't write that fallback yet in since I'm just going to put unique names on all my iframes.

Sarah Goldman added 3 commits September 25, 2013 15:41
… well as the height to the parent and then only resizing the iframe with the matching src attribute; Cleaned up the fallback code to both set and check the height hash on the frame. This is still blocked by cross-domain scripting restrictions, however it is not breaking the page in IE7
…href to iframe src. This will allow navigation to new pages within a responsive frame to continue to resize as long as new pages also call allow embedding
@ghost ghost assigned jaredbiehler Sep 26, 2013
@inadarei
Copy link
Contributor

Cool! Thanks.

// Sets the height of the iframe
setHeight: function (elem, height) {
height = height + 130;
$('iframe[name="' + elem + '"]').css('height', height + 'px');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check the name attribute and fall back to the src. Having this would break a lot of old code, and is very avoidable.

I'm thinking something like this:

var iframeName = $('iframe[src="'+elem+'"]');
if(iframeName.length){
  //We have the iframe, lets update the css
}else{
  //Fallback to src lookup
}

The other idea I had is we could pass the name or src in the message. Any thoughts?

@mbseid
Copy link
Contributor

mbseid commented Sep 27, 2013

Thanks for the PR. Overall, it looks pretty awesome, and I love the idea of having multiple iframe support within a document. I tried running it locally, and ran into some issues as I mentioned above. The biggest issue is the hardcoded "padding" height. It caused my iframe to grow to infinitum. Lets see if we can figure out a way to resolve that.

@sarahgoldman
Copy link
Author

I added the 130px height padding because, on the page I was framing in, the height alone was coming up just a little short and causing a scrollbar and then an infinite loop due to the scrollbar changing the size of the frame. So I added a little padding on the height to be safe and it was working for me. I didn't see any infinitely growing iframes.

Also in regard to the name vs. src, yes, there should be a fallback to src on both sending the message and grabbing the iframe. So if the window has a name send it, if not send location.href. And then on the parent side you could use a regex to check if you are receiving an href or a name and handle accordingly.

@mbseid
Copy link
Contributor

mbseid commented Sep 27, 2013

Thanks for the response. The padding hd been a problem for a little bit.
All browsers are different and their is no simple solution. Which browser
were you testing on? I'm working on a Mac with Chrome.

I can assist on the fallback. It'll be on Monday, but I don't think it will
be hard.

On Friday, September 27, 2013, Sarah Goldman wrote:

I added the 130pc height padding because for the page I was framing in the
height alone was coming up just a little short and causing a scrollbar and
then an infinite loop due to the scrollbar changing the size of the frame.
So I added a little padding on the height to be safe and it was working for
me. I didn't see any infinitely growing iframes.

Also in regard to the name vs. src, yes, there should be a fallback to src
on both sending the message and grabbing the iframe. So if the window has a
name send it, if not send location.href. And then on the parent side you
could use a regex to check if you are receiving an href or a name and
handle accordingly.


Reply to this email directly or view it on GitHubhttps://github.com//pull/21#issuecomment-25278040
.

@sarahgoldman
Copy link
Author

I tested it in Chrome, Safari, FF, and IE8+ and didn't see any infinitely growing iframes. But I only tested it with two frame srcs. Not sure if the css or content on the framed page might be affecting the height calculation in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants