954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Dynamicallu Resizeing IFRAME based on content

I'm stuck with a big problem. :sad: :sad: :sad:
I have the following script resizeing my iframe based on height. The problem is if my site is on one domain say http://mydomain.company.com and the target page is on another domain say http://anotherdomain.mycompany.com the script does not resize the page. I cannot add anything to the pages i am linking to because they live in a CVS repository so i cannot call a function or passs information in that way.

is there any way to make my script work? I'm so fustrated, I'm so close! help!


which uses the following iframe

JaxsWastedLife
Newbie Poster
8 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

I've dealt with this scenario extensively, so I think I understand what you are trying to do and what you are asking.

As you've discovered, you cannot use client-side script to work with the document object model of remote site content. (Even if that "remote" site is on your own server--just another domain.) I don't have a perfect solution, but I have 2 options for you based on your needs.

1. Don't use an IFRAME, use a normal FRAME. For example, your content on the top or left, and the content frame on rest of page. It will auto-size for content whereas an IFRAME will not. (I also recomment avoiding frames wherever possible, but for some applications, they really fit the bill.)

2. Do you just need the display of the remote content? If so, you can screen scrape the remote content server-side, then display it in your page. If you do this, it becomes your "own" content, and you can do anything script-wise you want. Most likely, though, you actually want your users to work with the content--clicking links, etc. that reload from the remote domain. In this case, a screen-scraping solution does not help you.

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 
NimbusSoftware
Newbie Poster
4 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

While I would agree with Troy, if you still need to do it with iframes, this might work. I havent tried it out with your specific problem though.

In the past I have had special situations where I needed to change html so I used tags. This might be unconventional but try this

(your iframe tags go here)

Then with javascript try this

document.getElementById('myframe').innerHTML = yourHTML

Where yourHTML has new iframe html with new properties.

Like I said, I havent tried with iframes but it works in lots of other areas
-B

bwest
Junior Poster in Training
57 posts since Jul 2004
Reputation Points: 14
Solved Threads: 1
 

You can do this by using the following method;
http://dhtmlnirvana.com/content/dhtml/autofit/autofitiframe.html

Eddie Traversa

DHTML

http://dhtmlnirvana.com/

Spiritual Blog

http://www.truthrealization.com/

Eddie Traversa
Newbie Poster
20 posts since Jul 2005
Reputation Points: 11
Solved Threads: 0
 
You can do this by using the following method; http://dhtmlnirvana.com/content/dhtml/autofit/autofitiframe.html

Thanks for the post Eddie! Looks like some helpful info. However, Jaxs, this will not work for you since you do not control the page being loaded into the IFRAME. Notice this from the pate Eddie posted: It is important to note that the script is placed in the page that is being loaded into the IFrame.
The page you are loading into the IFRAME is a third-party page that you do not control. Right?

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

I have control of the pages but due to the fact that there are thousands of them of all different types that live in a CVS Repository, adding code to every page is not the solution.

The reason that scripts don't work across a different domain is http://msdn.microsoft.com/workshop/author/om/xframe_scripting_security.asp
is there a way i can get around this?

Also I started a new thread because i wanted to try to use a hidden iframe as a buffer for a i am not sure how to implement it though. I cannot seem to find any good documentation online about it.

JaxsWastedLife
Newbie Poster
8 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 
Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

Troy,
Thanks!!! I think you are on to something there.
I tried the code you gave me.
From my menu, when i send links to the frame target, fred_frame for instance, it loads the page i want in the div area, but when i click a link from the newly loaded page it does not open inside the div it overwrites the entire page. :sad: The links are not relative.
How do i have all the links from the loaded pages stay in the frame like they do in regular iframes , without the addation of the target="" to every link. Shouldn't the links stay in the frame because they are loaded in the frame? :confused:

JaxsWastedLife
Newbie Poster
8 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

No, once you copy the source from the frame into your div, it's in your parent page. Links clicked in that page will open in that same page by default.

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

Thanks Troy you have been more helpful than google! :mrgreen:

JaxsWastedLife
Newbie Poster
8 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

I wrote a PHP proxy script that has some applications relevant to this thread, so thought I'd update the thread with this....

If your webserver supports PHP, I have a script that is a solution to the cross-domain security issues when doing things such as AJAX requests, etc. Instead of directly requesting the content, request my proxy.php passing in the real URL that you want. The proxy.php script will go fetch the content for you and forward back that response to your client script. It echoes back the full headers and response body.

proxy.php
http://www.troywolf.com/articles/php/class_http/proxy.phps

One problem people run into when using a proxy to get content is that relevant URLs in links break. You can solve this by parsing the body text, look for links, and if the link does not start with 'http://', insert the original site url. It's not exactly a simple thing to do, but a solution I've built in the past.

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

hi!! you can allow the iframe to autosize the height and width with the following Attributes:
width="100%" height="100%"

naksindia
Newbie Poster
1 post since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You