简体   繁体   English

了解何时提交 iFrame 中的表单的事件

[英]Event to know when a form in an iFrame has been submitted

Ok so I have an iframe on the Contact page of my website.好的,所以我在我的网站的联系页面上有一个 iframe。

The src of the iframe points to another file containing a Google Docs form. iframe 的 src 指向另一个包含 Google Docs 表单的文件。

Once the Google docs form is submitted, the page is redirected to a Google page saying that "your response has been recorded".提交 Google 文档表单后,该页面将被重定向到显示“您的回复已被记录”的 Google 页面。

I have this form inside an iframe so that it doesn't redirect viewers away from my entire site, but instead only the iframe document is redirected.我在 iframe 中有此表单,因此它不会将查看者重定向到我的整个站点,而是仅重定向 iframe 文档。

This all works fine, But I want to show my own message instead of the Google "your response has been recorded".这一切都很好,但我想显示我自己的消息而不是谷歌“你的回复已被记录”。

To do this, basically I want to know when the iframe has been redirected and/or (preferably) the form has been submitted.为此,基本上我想知道 iframe 何时被重定向和/或(最好)表单已提交。

Things i've tried...我尝试过的事情...

  • onhaschange="" inside the iframe element iframe 元素内的 onhaschange=""

  • onsubmit="" inside the form element (which is in the iframe src file) onsubmit="" 在表单元素内(在 iframe src 文件中)

Any other ideas?还有其他想法吗?

Look at this answer: iFrame src change event detection?看这个答案: iFrame src change event detection?
Create a function to check if the loaded content is from Google and react properly.创建一个 function 以检查加载的内容是否来自 Google 并做出正确反应。

Too late I guess but... here's my answer.我想为时已晚,但是...这是我的答案。 I've had the same quiz today.我今天也有同样的测验。

function getIframe(iframeElement){
    //retrieves the document element inside of an iframe
    return iframeElement.contentDocument;
}

var iframeElem = document.getElementById('iframeId');

iframeElem.onload = function(){
    //onload also catches form post sending
    var iframeDoc = getIframe( iframeTpv );
    //retrieves the height of the content's body
    var contentHeight = iframeDoc.body.scrollHeight;
    //do something ... 
}

Old question but I think I found a simple solution:老问题,但我想我找到了一个简单的解决方案:

HTML: HTML:

<iframe src="google_form_link" onload="changed()">Loading…</iframe>

JS: JS:

var change_count = 0;

function changed() {
    if (change_count === 1 /* NUMBER OF FORM PAGES */) {

        /* DO SOMETHING */

    }
    else {

        window.change_count += 1;

    }
}

For same domain.对于同一个域。 How to detect before iframe loaded?加载 iframe 之前如何检测? some like有些喜欢

$('#iframe').contents().find('a').click(function() {
    $('#iframe').animate({opacity:0.1},30);
});

Have some one other right way?还有其他正确的方法吗? Some like iframe blur, src out... event.有些像 iframe blur, src out... 事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM