Is it possible for the IFRAME module to automatically detect the height of the target url and scale accordingly. This would mean the IFRAME always displays without a scroll bar.

And if not, can we have master settings for width and height? i.e. not exposed to the users in a cck field?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

neffets’s picture

1) it is possible to detect the height of the iframe, BUT only if the iframe-content is from the same domain (same-origin-policy by the browsers)
see:

get http://schuessler-reisen.de/sites/all/js/iframe_resize.js and adjust the iframeid Variable at top.
You have to include it in your master-Template page.tpl.php

2) You can give master width and height, when You add the iframe-cck-fields on your "content-types" (e.g. story, btw. page)
(if this is not working for You file a bug-report please)

n

neffets’s picture

Status: Active » Closed (fixed)
Leiche’s picture

Version: 6.x-1.2 » 6.x-1.3

Hi,

thats the answer that I was searching for.
But I have a small problem with it, because I'm not a great programmer.

What is the "iframeid" and where can I look it up?
How do I include the JavaScript into my page.tpl.php?
Can I use my theme page.tpl.php?

Sorry for this stupid questions, but like I said I'm totally new to tweaking Drupal files in this way.

Cheers Leiche

Leiche’s picture

Status: Closed (fixed) » Active

Doh ... sorry for this post, but I forgot to reactivate the issue :(

MarcElbichon’s picture

tobiassjosten’s picture

Status: Active » Needs review
FileSize
5.63 KB

I rolled a patch which allows you to set an automatic height. Because resizing an iframe is only possible between the same domain, I also added an proxy PHP script that will serve your external pages through your own domain. All relative paths are kept by use of the base tag.

In short, this lets you set the height to 'auto'.

tobiassjosten’s picture

FileSize
5.79 KB

Added functionality to proxy also URLs with paths, like example.com/page, and URLs with queries, like example.com?query=example. I also fixed the base tag injection so that it considers paths, for relative URLs.

gwink’s picture

This is not working for me. I have this

I also tried with iframe id="iframe-0"
Finally, I tried height="100%"

any thoughts/ideas?

tobiassjosten’s picture

Did you apply the patch successfully? Have you tried setting the height to 'auto' instead of '100%'?

Your problem could also be related to a bug in Iframe, #664838: Conflicting iframe IDs, if you are using more than one iframe per page.

tobiassjosten’s picture

FileSize
5.83 KB

Realizing this wont work too well on cached iframes (cached CCK field, cached block, cached view, etc) I decided to put the javascript inclusion in hook_init() and made it work on all iframe tags with an 'auto' height. This also helped clean the code up some.

amitaibu’s picture

From reading code:
- Why the use of curl and not drupal_http_request?
- Maybe instead 'auto' we can accept 0. I think it's better for a field to be of the same type (a number and not mixed).

manoelhc’s picture

The function drupal_http_request() doesn´t support proxy. That is so bad.
Curl should support DNS cache.

mario0455’s picture

Hi,
can someone please explain step by step, how to do all this?

" You have to include it in your master-Template page.tpl.php" - where to include very top before "php", this cause top errors, body errors... head errors, or it is some part of the code.

"iframe_resize.js " - i have to create this file in my template master folder?

"You can give master width and height" -What this means, master? "100%" "auto"

A big part of us are only common mortals ;-)
Thank you for your time.

tobiassjosten’s picture

The proxy script doesn't bootstrap Drupal, for performance reasons, and so it doesn't have access to drupal_http_access(). You do have a point though - that function, I believe, have a fallback for curl-less environments and so should this proxy.

It turns out IE doesn't support resizing like this, at all. I don't know why or if it can be made to work. One solution would be to put the "auto" metadata outside the height property and let the height value only control the initial height of the iframe. If the tag supports it, maybe rel="autoheight" would work?

Scott M. Sanders’s picture

Subscribing.

Frederic wbase’s picture

Hello

I have downloaded version 6x 1.3 of the module and aplyed the path to it, but it doesen't work for me. The iframe always gets the height of 700px.

The iframe is loaded from another domain.

Anyone has an idea?

grts

frederic

alebening’s picture

please explain me more deatil how to adjust the frameid and how to include it in master template page.tpl.php...
sorry for dumb question...:D

chipway’s picture

@tobiassjosten,
Did you apply your patch to the latest 6.x-1.8 version ?

For me it works for same domain content in iFrame, but i still can't make it work with the proxy script.

chipway’s picture

I applied patch #10 on the latest 6.x-1.8 version, then fixed it, but there is still an issue :

First content loaded in the iframe gives the right height to the iframe, but as soon as i click in the iframe, the height is no more fitted to new content (keeps first content height), as height is evaluated on onload of my page.

I keep investigating the issue and listening to any idea to fix it.
Thanks

neffets’s picture

Version: 6.x-1.3 » 6.x-1.8
Assigned: Unassigned » neffets

My 10cents:

  1. "auto": Its not a good idea to start without a predefined height into rendering the page. I suggest to let be the height in pixel or %.
  2. You can use the 'Additional CSS Class' to add a class "autoresize". this is good catchable with selector iframe.autoresize.
  3. I would prefer loading the javascript only if "autoresize" is selected in css-class and only if the url is from same domain (see next point)
  4. Warning do not use a proxy module! I will never support it, its an "open-proxy" for the whole world. If You will ever support proxying You have to "close" it per module-defined-action "/iframe/load/<nodeid>/<iframeid_or_instanceid>" which will internally get the iframe-url by node-id and make the proxy call not open for any url of the world, but "close" it up to the one and only defined url by the redakteur!
neffets’s picture

FileSize
4.66 KB

iframe.js added to git.
Because I prefer adding "autoresize" to the class definition, I enabled css-class-editing on single-node-level.
The js reacts on iframe.autoresize selector.

If one want to add the foreign-domain support with a menuaction a la "/iframe/load//

", he is invited. Inside it can use the preferred drupal_http_request method. So its save against open-proxy problem. What would be the best method to support resizing not only at load of page? Should we recall every 10 seconds, or does exist an event "iframe-changed / location of iframe changed"?
marinex’s picture

Hi, I came across a solution based on easyXDM. Maybe it should be good solution for cross domain communications between drupal sites.

Marinex

neffets’s picture

Version: 6.x-1.8 » 7.x-1.x-dev
Issue summary: View changes
Status: Needs review » Fixed

Added the "autoresize"-feature in the drupal 7 branch too.
(its only works for same origin -iframes.)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.