[英]Event to know when a form in an iFrame has been submitted
好的,所以我在我的網站的聯系頁面上有一個 iframe。
iframe 的 src 指向另一個包含 Google Docs 表單的文件。
提交 Google 文檔表單后,該頁面將被重定向到顯示“您的回復已被記錄”的 Google 頁面。
我在 iframe 中有此表單,因此它不會將查看者重定向到我的整個站點,而是僅重定向 iframe 文檔。
這一切都很好,但我想顯示我自己的消息而不是谷歌“你的回復已被記錄”。
為此,基本上我想知道 iframe 何時被重定向和/或(最好)表單已提交。
我嘗試過的事情...
iframe 元素內的 onhaschange=""
onsubmit="" 在表單元素內(在 iframe src 文件中)
還有其他想法嗎?
看這個答案: iFrame src change event detection?
創建一個 function 以檢查加載的內容是否來自 Google 並做出正確反應。
我想為時已晚,但是...這是我的答案。 我今天也有同樣的測驗。
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 ...
}
老問題,但我想我找到了一個簡單的解決方案:
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;
}
}
對於同一個域。 加載 iframe 之前如何檢測? 有些喜歡
$('#iframe').contents().find('a').click(function() {
$('#iframe').animate({opacity:0.1},30);
});
還有其他正確的方法嗎? 有些像 iframe blur, src out... 事件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.