Here is a question I've yet to find an answer to.

I have some javascript I'd like to be dynamically inserted into a page when its called. The set up is this.

I have an <iframe> in my site and the pages that get linked to externally to go into the iframe obviously dont change the size of the iframe without a little help. The idea behind it is this.

I can resize the <iframe> based on the page that is being framed providing I put a tiny chunk of code in it. Thats not possible if I dont own the pages so the <iframe> will just add scroll bars which is very unattractive.

I'd like to take this script below and have it inserted into every EXTERNAL page I frame dynamically. In fact even a link to a .js would work.

<script type="text/javascript">
function goSetHeight() {
  if (parent == window) return;
  // no way to obtain id of iframe object doc loaded into? no parentNode or parentElement or ...
  else parent.setIframeHeight('ifrm');
}
</script>

So for instance if I took my web site and put an iframe in it with Daniweb.com as the page, I'd like this code to somehow be an addendum or part of the final render of daniweb.com for instance.

Is this insane or what?

Jared

You could use curl or file() to get the page and then add your code before sending it to the iframe. Doesn't sound very ethical though if you don't own the page.

You could use curl or file() to get the page and then add your code before sending it to the iframe. Doesn't sound very ethical though if you don't own the page.

Ethics, yeah the alteration isn't one that should raise that question at all. Its just a way to get the page size so it can be framed correctly.

Jared

Browser security will not allow you to run scripts against pages not from your own webserver, but Danceinstructor is right, you could do this server-side. It's more work, of course, but server-side is the way to accomplish your goal.

Check out PHP's curl support, or better yet, my class_http.php makes it very easy to grab remote pages server-side.
http://www.troywolf.com/articles/php/class_http/

This article has been dead for over six months. Start a new discussion instead.