Dynamicallu Resizeing IFRAME based on content

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jun 2005
Posts: 8
Reputation: JaxsWastedLife is an unknown quantity at this point 
Solved Threads: 0
JaxsWastedLife JaxsWastedLife is offline Offline
Newbie Poster

Dynamicallu Resizeing IFRAME based on content

 
0
  #1
Jul 8th, 2005
I'm stuck with a big problem.
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!


<!--this script auto resizes the height of the iframe based on contents-->
<script type="text/javascript">
<!--
function resize_iframe(){
document.getElementById("_iframe").height=768 // required for mozilla/firefox bugs, value can be "", null, or integer
document.getElementById('_iframe').height=window.frames["_iframe"].document.body.scrollHeight
}
// -->
</script>

which uses the following iframe
<iframe width=96% id="_iframe" name="_iframe" src="intro.htm" scrolling="no" frameborder="no" ALLOWTRANSPARENCY="true" onload=resize_iframe();></iframe>
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Dynamicallu Resizeing IFRAME based on content

 
0
  #2
Jul 8th, 2005
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 Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 4
Reputation: NimbusSoftware is an unknown quantity at this point 
Solved Threads: 0
NimbusSoftware NimbusSoftware is offline Offline
Newbie Poster

Re: Dynamicallu Resizeing IFRAME based on content

 
0
  #3
Jul 9th, 2005
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 57
Reputation: bwest is an unknown quantity at this point 
Solved Threads: 1
bwest's Avatar
bwest bwest is offline Offline
Junior Poster in Training

Re: Dynamicallu Resizeing IFRAME based on content

 
0
  #4
Jul 11th, 2005
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 <div> tags. This might be unconventional but try this

<div id="myframe">

(your iframe tags go here)

</div>

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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 20
Reputation: Eddie Traversa is an unknown quantity at this point 
Solved Threads: 0
Eddie Traversa Eddie Traversa is offline Offline
Newbie Poster

Re: Dynamicallu Resizeing IFRAME based on content

 
0
  #5
Jul 11th, 2005
You can do this by using the following method;
http://dhtmlnirvana.com/content/dhtm...fitiframe.html

Eddie Traversa

DHTML

http://dhtmlnirvana.com/

Spiritual Blog

http://www.truthrealization.com/
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Dynamicallu Resizeing IFRAME based on content

 
0
  #6
Jul 11th, 2005
Originally Posted by Eddie Traversa
You can do this by using the following method;
http://dhtmlnirvana.com/content/dhtm...fitiframe.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 Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 8
Reputation: JaxsWastedLife is an unknown quantity at this point 
Solved Threads: 0
JaxsWastedLife JaxsWastedLife is offline Offline
Newbie Poster

Re: Dynamicallu Resizeing IFRAME based on content

 
0
  #7
Jul 11th, 2005
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/a...g_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 <div> i am not sure how to implement it though. I cannot seem to find any good documentation online about it.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Dynamicallu Resizeing IFRAME based on content

 
0
  #8
Jul 11th, 2005
You are not going to get around the cross-domain scripting security.

If you are thinking you'll use a hidden IFRAME to load the remote-domain page, then in your page, script copying the IFRAME's content into your own DIV, you will have the same cross-domain security issue. BUT, here is how you can do this:
[HTML]
<html>
<head>
<script language="javascript">
function LoadDiv(id) {
document.getElementById(id).innerHTML = eval(id+"_frame.document.body.innerHTML");
}
</script>
</head>
<body>

<div id="fred"></div>

<iframe name="fred_frame" style="display:none;" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" src="somepageonmyserver.htm" onload="LoadDiv('fred');"></iframe>

</body>
</html>
[/HTML]

And you'll have the same problems as you would if you used server-side scripting to scrape the content then put it in your page. That is, relative links in the page will not work. Relative links to style sheets and javascripts will not work so the page may not look or function as expected.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 8
Reputation: JaxsWastedLife is an unknown quantity at this point 
Solved Threads: 0
JaxsWastedLife JaxsWastedLife is offline Offline
Newbie Poster

Re: Dynamicallu Resizeing IFRAME based on content

 
0
  #9
Jul 12th, 2005
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. 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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Dynamicallu Resizeing IFRAME based on content

 
0
  #10
Jul 12th, 2005
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 Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC