Support Forums

We encourage an open exchange of information. Ask your questions or make suggestions. We are here to help, but we also encourage all of you to help one another.
Click on the Subscribe Flag to be notified by email of replies to your post.
Current User: Guest Login Register
Please consider registering

Auto-Fit Your Embedded Survey

Add a New Topic Reply to Post
UserPost

1:51
February 6, 2008


johny

Member

johny

posts 84

(applies to iFrame surveys only)

does your survey have multiple pages? or, does the length of your survey change frequently? do you add or remove questions frequently.

do you find that the height of your iFrame is sometimes too short, cutting off the bottom of the survey? is your iFrame sometimes too tall, pushing down your content beneath the survey?

this technique is for you.

look here for an example. fill out the survey to see the autofit in action:
http://laptopacademy.net/wordpress/signup

i’ll share the code in my next post.

2:09
February 6, 2008


Chad

Moderator

posts 754

Wonderful johny,
Nice job, I love how that survey looks.

-Chad

2:19
February 6, 2008


johny

Member

johny

posts 84

(thanks chad!)

this method is not for the faint of heart.

it will require a bit of script, and you’ll need to upload a couple of files to your web-host.

your visitors must have javascript enabled, which, according to several , sources i checked, is about 95% of all users. this method includes a fall-back, for users without javascript.

there are several steps. i’ll present each step in a separate post, for clarity.

2:24
February 6, 2008


johny

Member

johny

posts 84

first step.

Name Your iFrame
add the following snippet to your iFrame script:

name="surveyFrame" id="surveyFrame"

then give your iFrame a height tall enough to accomodate your tallest survey-page. this is the fallback, for users who do not have javascript:

height="600"

when you’re done, it will look something like this:

<iframe src="http://laptopacademy.signup.sgizmo.com/" name="surveyFrame" id="surveyFrame" style="overflow: hidden" allowtransparency="true" frameborder="0" height="600" scrolling="no" width="100%"></iframe>

2:35
February 6, 2008


johny

Member

johny

posts 84

next step.

WordPress users will want to disable the visual editor for this step: go to Users/Your Profile, and UNcheck “Use the visual editor when writing”

Script On Your Page

Paste this script anywhere into your webpage, where the iFrame is embedded:

<script type="text/javascript"> function resizeIframe( height ) { var iframe = document.getElementById( "surveyFrame"); iframe.setAttribute( "height", height ); } </script>

4:43
February 6, 2008


johny

Member

johny

posts 84

next step.

Upload Files To Your Web Host

download the following file, called “autofit.zip”, and unzip it.

http://www.esnips.com/doc/1d3a780e-a4c4-4c01-af94-d59b19455fb3/autofit

then upload the files to the same directory as the location of your webpage which contains your survey iFrame. advanced coders can put them into a “scripts” directory, or other standard folder.

WordPress users should put them outside your WordPress directory, to avoid any conflicts.

make note of the full path to the files you just uploaded to your web server. this is the public “http” path to the files.

4:44
February 6, 2008


johny

Member

johny

posts 84

next step.

Script Your Survey Template

go to the SurveyGizmo.com/Edit Survey/”Look and Feel” page.

scroll down to “This Theme’s HTML Template”.

scroll inside the html template to the bottom, and paste the code below.

after pasting, you MUST change the urls to point to the files you just uploaded to your server.

<iframe id="HiddenIframe" width="1" height="1" style=" position : absolute; top : 0px; left : 0px; visibility: hidden; "></iframe>

<script type="text/javascript" src="http://PATH/TO/YOUR/WEBSERVER/fx.js">
</script>

<script>loadHiddenIframe(
“http://PATH/TO/YOUR/WEBSERVER/hiddeniframe.html”
)</script>

don’t forget to click the ’save’ button.

4:56
February 6, 2008


johny

Member

johny

posts 84

That’s it. Give it a try. Open your webpage containing the survey. You may need to clear your browser cache for it to work.

How It Works
Essentially, the parent page resizes the iFrame after it knows how tall the survey is. But there are a few obstacles.

Because of the way browsers work, the parent page cannot know the size of the survey– only the survey itself knows. Browsers will not allow the iFrame to talk to the parent, because they are in different domains. It’s a security protection.

So the survey has to talk to the parent in a roundabout way. The roundabout way is another iFrame, embedded inside the survey. The web-page loaded into that inner iFrame happens to be in the same domain as your website. Therefor, that inner iFrame can talk to your parent page.

So the survey has to tell the inner iFrame how tall it is. How does it do this? Look at the url of this page in your address bar. See where it says
?forum=3

That’s a bit of extra information tacked onto the end of the address. This is how the survey communicates with the inner iFrame– it embeds it’s height value into the address of the inner iFrame.

Then the inner iFrame grabs the height from it’s own address, and sends it back up to the parent page. Then the parent resizes the survey iFrame. Pretty clever, eh?

Look at the comments in the two downloaded files, for more explanation.

This code is based on the method explained here:
http://blog.johnmckerrell.com/2006/10/22/resizing-iframes-across-domains/

6:52
April 17, 2008


Robert

Guest

johny said:

next step.


Script Your Survey Template


go to the SurveyGizmo.com/Edit Survey/”Look and Feel” page.


scroll down to “This Theme’s HTML Template”.


scroll inside the html template to the bottom, and paste the code below.


after pasting, you MUST change the urls to point to the files you just uploaded to your server.


<iframe id=”HiddenIframe” width=”1″ height=”1″ style=” position : absolute; top : 0px; left : 0px; visibility: hidden; “></iframe>


<script type=”text/javascript” src=”http://PATH/TO/YOUR/WEBSERVER/fx.js”>
</script>


<script>loadHiddenIframe(
“http://PATH/TO/YOUR/WEBSERVER/hiddeniframe.html”
)</script>


don’t forget to click the ’save’ button.


***New to this****

The above part of your script is generating an invalid character error. I don’t know any Java could you please tell me how to fix it. :)

12:02
April 18, 2008


Chad

Moderator

posts 754

Thanks for this johny!

Hi Robert,
If you’re copying and pasting this script change all the ” to “. So delete all the double quotes and re-type them in.

Hope this helps,
Chad

8:39
May 12, 2008


martin

Guest

How It Works
Essentially, the parent page resizes the iFrame after it knows how tall the survey is. But there are a few obstacles.


Because of the way browsers work, the parent page cannot know the size of the survey– only the survey itself knows. Browsers will not allow the iFrame to talk to the parent, because they are in different domains. It’s a security protection.


So the survey has to talk to the parent in a roundabout way. The roundabout way is another iFrame, embedded inside the survey. The web-page loaded into that inner iFrame happens to be in the same domain as your website. Therefor, that inner iFrame can talk to your parent page.


So the survey has to tell the inner iFrame how tall it is. How does it do this? Look at the url of this page in your address bar. See where it says
?forum=3


That’s a bit of extra information tacked onto the end of the address. This is how the survey communicates with the inner iFrame– it embeds it’s height value into the address of the inner iFrame.


Then the inner iFrame grabs the height from it’s own address, and sends it back up to the parent page. Then the parent resizes the survey iFrame. Pretty clever, eh?


Brilliant! Thanks. I am so glad you have this info posted here. This is truly the solution I was hoping to find in dealing with a cross server iframe presentation. Again, thank you!

10:52
July 7, 2008


Dave

Guest

Thank you very, very much. I used the guts of your code to solve a similar problem across two domains that we run and I doubt I would have got it on my own.

12:45
July 9, 2008


jp

Guest

Thank you so much for this posting. It works great.

Though I have one question…

First iframe page is 1000px height
Second iframe page is 1500px height

Within the iframe, I am giving the user the option to go back a page and change their information, if needed.

When a user goes BACK from the second iframe page to the first iframe page, it does not resize again. Therefore the first iframe page is 1500px height - with alot of open space at the bottom.

Is there a way to call the resize function again, when they hit the back button?

Any help/ideas are appreciated.

Thanks!

4:24
July 10, 2008


johny

Member

johny

posts 84

Is it possible something is missing from your setup? Check out my demo, above– the iFrame resizes when the back button is clicked.

Glad this code is helping people– cross-domain scripting is one of those puzzles “they” say can’t be done :)

7:59
July 15, 2008


Jay

Guest

I have similar issue as JP. and also a question.

first… Where does the getFirstParam function get called ? looks like never. maybe I’m blind.

2nd, just like JP, I have an iframe of a knowledge base (remotely hosted)

How can I get proper height for each page ? JP, did you find a solution ? It appears that once the hidden iframe gets loaded, it never gets reloaded, therefor, causing it to never resize properly (although if you’re using the default fx.js it appends 50 pixels on each load)

thanks in advance.

Add a New Topic Reply to Post


Reply to Topic: Auto-Fit Your Embedded Survey

Guest Name (Required):

Guest EMail (Required):

Guest URL (required)

Math Required!
What is the sum of: 9 + 4        (Required)

Topic Reply:


 
© Simple:Press Forum - Version 3.1.4 (Build 357)