944,021 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 4268
  • PHP RSS
Feb 24th, 2006
0

Dynamic Include

Expand Post »
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.

PHP Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. function goSetHeight() {
  3. if (parent == window) return;
  4. // no way to obtain id of iframe object doc loaded into? no parentNode or parentElement or ...
  5. else parent.setIframeHeight('ifrm');
  6. }
  7. </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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
php4ever is offline Offline
68 posts
since Feb 2005
Feb 24th, 2006
0

Re: Dynamic Include

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.
Reputation Points: 17
Solved Threads: 14
Posting Whiz
DanceInstructor is offline Offline
355 posts
since Feb 2005
Feb 25th, 2006
0

Re: Dynamic Include

Quote originally posted by DanceInstructor ...
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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
php4ever is offline Offline
68 posts
since Feb 2005
Mar 4th, 2006
0

Re: Dynamic Include

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/
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Declaring functions
Next Thread in PHP Forum Timeline: Need some help with parsing an XML file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC