if you include a URL from a different domain then the sites domain
the adjustHeight function does not work properly because it can't access the

window.frames[obj.name].document

because it would be a SECURITY RISK ...

Anybody know of a work around to this, anybody has implemented such a solution

Comments

MarcElbichon’s picture

You can't.
The only way is to include in the iframe page a function to resize parent.getElementById('iframeid') size.

giorgosk’s picture

Marc
we can put the following code as you say inside the iframe content (iframe src page)

<script type="text/javascript">
	function setHeight(){
		parent.window.document.getElementById("frame").style.height = document.body.scrollHeight + 30;
	}
	window.onload=setHeight;
</script>

and it works perfectly when both src page is on the SAME DOMAIN
but it give "access denied" when src page is on a DIFFERENT domain

as I suspected its a SECURITY RISK for both the iframe and the iframe src to be able to manipulate one another ...

--------------------------------------

I was thinking of another possible workaround

Having a javascript function increase the Height of the "iframe" untill the scrollbars dissapear but I can't find a way to check if/when scrollbars are visible or not. Any ideas ?

MarcElbichon’s picture

As you said, security does not accept access to page in differents domains. So your suggestion to increase height will not work as you need to access to parent page to do this !!!

No other idea !!!

giorgosk’s picture

Maybe I don't understand you but maybe I was not clear enough on the previous post

I can actually do it with the following example

I incrementally increase the iframe height until the scrollbars dissappear
and all is done from within the CALLING page (so no external domain is involved)

<html>
<head>
<script type="text/javascript">
 	function setHeight(){
		for ( i=0; i<2000 ;i+=50 ){
			document.getElementById("frame").style.height = i;
			//if scrollbars are not visible 
			//break;
		}
	}
	window.onload=setHeight;
</script>
</head>
<body>
<iframe src="http:// externaldomain. com/page.html"></iframe>
</body>
</html>

BUT I don't know how to check if the scrollbars are not visible

MarcElbichon’s picture

giorgosk’s picture

Title: adjustHeight only works with URLs from same domain » adjustHeight for EXTERNAL URLs
Category: support » feature
Issue tags: +iframe, +external URL, +adjust height

Marc
I have hacked your module in such a way that other people might find useful, thus I am proposing a feature request

When the url is EXTERNAL one can put an extra attribute for your iframe filter (external=yes) to tell it that the URL is external and that regular javascript WON'T WORK and another one to tell it the combined height of header + footer (headerandfooterheight=150)

With this information my code can assign a height to the iframe = window.height - headerandfooterheight thus creating a page with no window scrollbars but only iframe scrollbars (which is less confusing to the user)

and here is how I did it (but don't know enough to create a patch)

add in adjustHeight.js

function getDocHeight() {
	//IE
	if(!window.innerWidth){
		//strict mode
		if(!(document.documentElement.clientHeight == 0))	{return document.documentElement.clientHeight;}
		//quirks mode
		else{ return document.body.clientHeight;}
	}
	//w3c
	else{return window.innerHeight;}
}
function setHeight(obj,hfheight){
	obj.style.height = getDocHeight() - hfheight + 'px';
}
function init(obj,hfheight){
	setHeight(obj,hfheight);
	if (window.attachEvent) {
		window.attachEvent("onresize", function() {setHeight(obj,hfheight);} );
	} else {
		window.addEventListener("resize", function() {setHeight(obj,hfheight);} , false);
	}
}

add this in insertframe.module

	if ($iframe_params["height"] == "100%") {
		$onload = "onload='adjustHeight(this," . $iframe_params["offset"] . ")'";
		$code = "";
	}
// start of additional code - on line 56
	if ($iframe_params["external"] == "yes") {
		$onload = "onload='init(this," . $iframe_params["headerandfooterheight"] . ")'";
	}
//end of additional code

ofcourse it might need some beautifying but it works and it even adjust the height of the iframe on window.resize

Hope it makes sense

MarcElbichon’s picture

Why don't you use height and scrolling properties ?
ie:

[[[www.drupal.org height=300px scrolling=auto]]]

giorgosk’s picture

StatusFileSize
new16.29 KB

I thought it was clear but here is an attempt to clear things

If you set the height to a small number then you might be loosing space on
tall screens (and it looks bad), if you set the height large then you get the
following problem:

you get 2 sets of scrollbars (the iframe + the window scrollbars)
thus it is a usability issue where the user has to
move the window scrollbar AND THEN the iframe scrollbar in order to
see something at the bottom of the iframe content !!!!!!!!!

With my solution the iframe get the height of the window (-header -footer heights)
thus Eliminating the window scrollbars ..... (one set of scrollbars)

Take a look at the attached screenshot (2 sets of scrollbars)

Here is where I have implemented this solution http://www.myhellas.com/flights
and you can see the problem LIVE (if you disable javascript, and make your viewport smaller than 500px)

Hope it makes more sense Now

MarcElbichon’s picture

StatusFileSize
new118.81 KB

Your site works with FireFox but not with IE 6 (see screenshot)
Thus, this works because your iframe's height is smaller than window's height. If you have a left or right pane greater than window's height, you'll see two scrollbars.

In you code, you only manage resizing of the browser window. Your iframe's height is fixed to a size. Could you post me your iframe filter code in the drupal page ( the [[[.....]]] code) ?

I think the better way is to set height and scrolling properties. I can add a "resize" property to manage resizing of the iframe according to browser resizing. What do you think of ?

giorgosk’s picture

Don't take into consideration IE6 in order to judge the code (I should have told you before I guess)
The site has a known issue with IE6 - the problem is the theme/template and it will be fixed soon
but the javascript code works PERFECT in ALL other MODERN browsers (IE6 is not exactly MODERN)

In you code, you only manage resizing of the browser window. Your iframe's height is fixed to a size. Could you post me your iframe filter code in the drupal page ( the [[[.....]]] code) ?

I am resizing the IFRAME HEIGHT ONLY but not the browser window, revisit the code please.

This is what I am using in the node

[[[domain.com/page.html height=610px scrolling=auto external=yes headerandfooterheight=150]]]

still specifying the height just in case javascript is disabled.

I think the better way is to set height and scrolling properties. I can add a "resize" property to manage resizing of the iframe according to browser resizing. What do you think of ?

I don't completely understand this part but maybe we are talking about the same thing.
The height and scrolling are still specified in my scenario just in case javascript is disabled.

MarcElbichon’s picture

StatusFileSize
new1.41 KB

I think this is a specific feature. What I suggest you, is to add theming functions to do what you want.
With the attached version, you can do this.

  1. Create a javascript file (ie myinsertFrame.js) with the functions you want
  2. In your template.php, add this
    >
    function yourtheme_insertFrame_init() {
    	drupal_add_js(drupal_get_path('module', 'insertFrame') . '/myinsertFrame.js');	
    }
    function yourtheme_insertFrame_custom($onload, $iframe_params) {
    	if ($iframe_params["external"] == "") {return $onload;}
    	return "onload='init(this," . $iframe_params["headerandfooterheight"] . ")'";
    }
    
  3. test and tell me back if it's ok for you
giorgosk’s picture

I am not very good with drupal - I did not realize you could do this!!

I will check it as soon as I find a chance, but it should work ...

MarcElbichon’s picture

Assigned: Unassigned » MarcElbichon
Status: Active » Closed (fixed)

Added to new release

Anonymous’s picture

Version: 6.x-1.6 » 6.x-2.0
Category: feature » support
Status: Closed (fixed) » Active

Is this now a part of v2?

I tried setting height=100% but am still getting a small iframe window. What do I need to do to get an external URL in my iframe full height?

MarcElbichon’s picture

Due to browser security, extenal url can't be full height

Anonymous’s picture

Oh, I thought your post above meant you'd committed something to make this work...

MarcElbichon’s picture

No
GiorgosK wanted a page without scrolling (browser). See #8 attached file. So iframe isn't full height but with a specified size and would be resized when the browser is too.

Anonymous’s picture

Status: Active » Closed (fixed)

Ok, thanks.