在具有自动高度的IFrame中获取Google表单 [英] Getting a Google Form in an IFrame with Auto Height

查看:86
本文介绍了在具有自动高度的IFrame中获取Google表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个使用Google文档构建的表单,因为它看起来比从头开始要容易.通过将代码从google的页面复制粘贴到我的域中的一个代码,我可以使用此功能.

So I have a form that I built with Google Docs because it seemed easier than going from scratch. I've gotten this to work by copy-pasting the code from google's page to one on my domain.

我设法通过它在这里找到的这个可爱的小脚本来自动调整其高度:

I managed to get it to auto-size its height with this lovely little script I found here: http://www.frontpagewebmaster.com/m-89000/tm.htm (this is not another thread about HOW to dynamically resize an iframe)

function changeContent() { 
document.getElementById('contentDIV').innerHTML = window.frames['contentFRAME'].document.getElementsByTagName('html')[0].innerHTML;
} 

和我显示的页面上的iframe:

and the iframe on MY displayed page:

<div class="right" id="contentDIV">
<iframe id="contentFRAME" src="raw-form.html" name="contentFRAME" onLoad="changeContent()" style="height:0; width:0; border-width:0;">Loading...</iframe>
</div>

但是现在当我点击Submit时,确认或错误页面会在_parent窗口(可能是_top)中打开-而不是在iframe中(应该是默认值_self).target ="已贬值,无法正常工作.iframe中的任何链接也会发生这种情况.我尝试了几种不同的调整大小脚本,但是我不知道该怎么办?还是代码实际上不适合我的目的?我不确定...这是我的工作方式: http://fiendconsulting.com/60minutedesign/form-embed.html

But now when I hit submit, the confirmation or error page opens in the _parent window (might be _top) - instead of in the iframe (_self, which is supposed to be the default?). target="" is depreciated and doesn't work. This also happens with ANY link inside the iframe. I've tried a couple different resize scripts, but I don't know enough to figure it out? Or the code doesn't actually work for my purposes? I'm not sure... Here's what I have working: http://fiendconsulting.com/60minutedesign/form-embed.html

我需要的内容:可以在父"页面的首次加载时调整iframe内容的大小,并在_self框架/页面/所有内容中打开所有链接的内容.
我不在乎:调整iframe的大小以适合后续页面的内容.如果我单击iframe内的链接,则不需要iframe调整为我刚刚去过的页面的大小.

What I need: Something that resizes the iframe content on first load of the Parent page and which opens all links in their _self frame/page/whatever.
What I don't care about: Resizing the iframe to fit the content of subsequent pages. If I click a link inside the iframe, I don't need the iframe to resize to whatever page I just went to.

我是一名自学成才的程序员,在我的知识上有一些有趣的空白.我也刚开始学习JS和PHP,现在处于阅读,注释和蚕食"阶段.最好假设我不知道,如果您告诉我在哪里放置代码(哪个文档以及文档中的哪个位置),这将对我有很多帮助.:)

I'm a self-taught programmer and I have some interesting gaps in my knowledge. I also just started learning JS and PHP and am at the Read, Comment and Cannibalize stage. It's better to assume I don't know, and it would help me a LOT if you told me where to Put the code (which document and where in the document). :)

推荐答案

我不确定您要做什么,因为您提供的链接似乎无效;但是,我认为您的问题可能是由于您的调整大小功能引起的.

I'm unsure of what you are trying to do because the links you provided do not seem to work; however, I believe your problem might be because of your resize function.

您的功能:

function changeContent() { 
document.getElementById('contentDIV').innerHTML = window.frames['contentFRAME'].document.getElementsByTagName('html')[0].innerHTML;
}

采用元素"contentDiv",采用"iframe"的HTML,然后将其设置为内容div.这导致您的"iframe"不再存在.

You take the element 'contentDiv', you take the HTML of your 'iframe' and then you set the same to your content div. This results in your 'iframe' not existing any more.

例如:

假设我的内容div具有以下内容:

let's say my content div had this:

<div class="right" id="contentDIV">
<iframe id="contentFRAME" src="raw-form.html" name="contentFRAME" onLoad="changeContent()" style="height:0; width:0; border-width:0;">Loading...</iframe>
</div>

我的iframe仅具有1个链接:< a href ="www.example.com">示例链接</a>

My iframe has only 1 link: <a href="www.example.com">Example Link</a>

执行完功能后,contentDiv现在看起来像:

After your function, your contentDiv now looks like:

<div class="right" id="contentDIV">
<a href="www.example.com">Example Link</a>
</div>

您已经有效地删除了iframe,并将iframe的内容(链接)放入主div中.现在,如果您单击该元素,它将在同一页面上自动打开-即父级",但不再有父级!

you have effectively removed your iframe and put the contents of the iframe (the link) into your main div. Now if you click on the element, it'll automatically open on the same page - i.e. the 'parent' but there is no parent anymore!

因此,今后,您不应该替换内容;相反,您应该修改iframe的高度/宽度.看一下:调整iframe的宽度高度以适合其中的内容它

So going forward, you should not be replacing the content; instead you should be modifying the height/width of the iframe. Have a look at: Adjust width height of iframe to fit with content in it

这篇关于在具有自动高度的IFrame中获取Google表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆