开发者

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.

The src of the iframe points to another file containing a Google Docs form.

Once the Google docs form is submitted, the page is redirected to a Google page saying that "your response has been recorded".

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.

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.

Things开发者_JAVA百科 i've tried...

  • onhaschange="" inside the iframe element

  • onsubmit="" inside the form element (which is in the iframe src file)

Any other ideas?


Look at this answer: iFrame src change event detection?
Create a function to check if the loaded content is from Google and react properly.


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:

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

JS:

var change_count = 0;

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

        /* DO SOMETHING */

    }
    else {

        window.change_count += 1;

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜