问题在于:由于iframe,我的网站速度很慢。因此,我想延迟iframe加载,直到页面的其余部分加载。但是,我还需要在访问者看来之前将一堆参数附加到iframe src
。所以这是需要发生的事情的顺序:
setTimeout
?)iframe src
添加一堆参数
为了上下文,这里是网站:http://meetingtomorrow.com/(iframe实际上是在您点击蓝色"请求报价" sidetab后出现的表单)。页面上通常还有2个其他iframe:退出意图表单和另一个引用表单。
以下是我们当前如何启动将参数附加到网站上的iframe src
的功能:
<body onload="populateHiddenFields(document.forms['ga-tracking-form'])">
以下是我们当前如何将参数附加到iframe src:
function populateHiddenFields() {
jQuery('form#ga-tracking-form').each(function (index, element) {
var f = this;
f.source.value = source;
f.medium.value = medium;
f.term.value = term;
f.content.value = content;
f.campaign.value = campaign;
f.gclid.value = gclid;
f.segment.value = csegment;
f.numVisits.value = nVisits;
});
var loc = window.location.toString();
params = loc.split('?')[1];
document.getElementById("nsIframeSidetab").src = document.getElementById("nsIframeSidetab").src + '&custentity_web_lead_nab_parameter=' + encodeURIComponent(params) + '&custentity_ga_search_campaign=' + encodeURIComponent(campaign) + '&custentity_ga_search_source=' + encodeURIComponent(source) + '&custentity_ga_search_medium=' + encodeURIComponent(medium) + '&custentity_ga_search_keyword=' + encodeURIComponent(term) + '&custentity_ga_search_content=' + encodeURIComponent(content) + '&custentity_ga_search_gclid=' + encodeURIComponent(gclid);
document.getElementById("nsIframeExitIntent").src = document.getElementById("nsIframeExitIntent").src + '&custentity_web_lead_nab_parameter=' + encodeURIComponent(params) + '&custentity_ga_search_campaign=' + encodeURIComponent(campaign) + '&custentity_ga_search_source=' + encodeURIComponent(source) + '&custentity_ga_search_medium=' + encodeURIComponent(medium) + '&custentity_ga_search_keyword=' + encodeURIComponent(term) + '&custentity_ga_search_content=' + encodeURIComponent(content) + '&custentity_ga_search_gclid=' + encodeURIComponent(gclid);
document.getElementById("nsIframe").src = document.getElementById("nsIframe").src + '&custentity_web_lead_nab_parameter=' + encodeURIComponent(params) + '&custentity_ga_search_campaign=' + encodeURIComponent(campaign) + '&custentity_ga_search_source=' + encodeURIComponent(source) + '&custentity_ga_search_medium=' + encodeURIComponent(medium) + '&custentity_ga_search_keyword=' + encodeURIComponent(term) + '&custentity_ga_search_content=' + encodeURIComponent(content) + '&custentity_ga_search_gclid=' + encodeURIComponent(gclid);
return false;
最后一条关键信息。这是实际的iframe代码:
<iframe id="nsIframeSidetab" src="<?php echo 'https://forms.na2.netsuite.com/app/site/crm/externalleadpage.nl?compid=3373305&formid=65&h=AACffht_oVPvzBS2Q5xRFMm3YXYganqAV-g%3D&url=' . rawurlencode( get_permalink()); ?>" width="100%" height="350" frameborder="0" scrolling="no"></iframe>
这里的部分困难是iframe src
本身正在使用PHP函数动态填充URL的第一部分。它是一个WordPress网站,所以它拉进了固定链接(当前页面的URL)。然后在该永久链接之后,其余参数将通过JavaScript附加到URL。希望一切都有意义。
对于如何执行此操作的任何想法或建议(上面的步骤#1-4)将非常感谢!谢谢!