1

I am attempting to load a script that is on one of my web servers into a page that is on a hosted site with another service. Currently, I am using an iframe to make this work. The issue I have is the iframe cannot dynamically expand based on the php's output.

What has been suggested to me is trying to inject the php output into a div but I don't think that I can do that cross domain.

I am going from a web server at example.net/scripts, which I have full access to, and loading it in a page on example.us, which I have very limited access to since it is a hosted service (namely enjin).

What I need is a solution that will allow me to call the php script from the web server and display its output on the page in an element that can expand based on the output from the script. When it pulls the php script, it needs to display within the CSS parameters that are predefined in the CSS for the div (min-height, max-height) but only at the height of the elements of returned in the script.

To further clarify, I am using the php script to do a foreach loop for json output from an API from TwitchTV. When the foreach loops runs it builds an element structure for each of the returned results to display them as desired. I end up overflowing out of the iframe if i have too many returns and if i have no returns, it just returns a string and displays it, but at that point the iframe's height is too high.

Any examples anyone can give me or solution suggestions?

xanara
  • 11
  • 2
  • So: you have limited access to site A. Site A has an iframe which displays site B. Based on the output on site B, you want the iframe on site A to change size. Is that correct? – JakeParis Feb 26 '13 at 14:55
  • Yes, that's pretty accurate. If i can use something other than an Iframe it would be great but the biggest issue is getting the iframe, or whatever other element, to get it's height based on the output from the script on site B. – xanara Feb 26 '13 at 15:02
  • You can grab the cross domain content using a server-side proxy via CURL. – Diodeus - James MacFarlane Feb 26 '13 at 15:06
  • on the site I am going to, I can't use PHP otherwise the script would just be there. "Site B" gives me very basic access to things. – xanara Feb 26 '13 at 15:09
  • What can you do on site B? javascript? jquery? just html? – JakeParis Feb 26 '13 at 15:17
  • I should be able to load javascript, jquery and ajax in theory. The page already calls jquery-1.4.2.min.js, jquery-ui.min.js and jquery.autoresize.min.js if i can use something contained in one of those, that would be awesome. I can also give a link to a test page of mine if needed. – xanara Feb 26 '13 at 15:24
  • here is a link to the site so you can see what's loaded http://www.abyssgaming.us/testingstuff @JakeParis – xanara Feb 26 '13 at 22:38

1 Answers1

0

Since you can AJAX, your solution would be to use AJAX to call the code on the non-locked down site, and return the box with the stuff in it. On the locked-down site, process that code and then just stick it in a <div> on the locked-down site. And of course that div can expand to fit the content like usual.

If, for some reason, you have to use the iframe, just gather the height of the box with javascript (you could hide the box off to the left if need be with left: -9999px). Use that height information to set the height of the iframe. So you are basically loading the content of the iframe twice. Once through ajax just to get the height, and once through the actual iframe.

I don't really see any reason that the iframe should be necessary -- the process in the first paragraph should work fine.

JakeParis
  • 11,056
  • 3
  • 42
  • 65
  • I did this and tested it out with no luck. I believe that I am still hitting the cross server security issues with ajax calling files from another domain. That's why this issue was tricky in the first place. I used something like this http://pastebin.com/TNsRpNz6 to accomplish the load and then refreshes every 10 seconds, but this does not work cross domain. If I take this same script and put it on site a, it loads fine. On site b, it fails to load. – xanara Feb 27 '13 at 15:07