dsz1966 2016-07-02 16:51
浏览 653

在页面加载时延迟iframe,附加参数,然后在5秒后显示iframe

Here's the issue: My site is slow and it's because of iframes. Due to that, I want to delay the iframes loading until the rest of the page loads. However, I also need to append a bunch of parameters to the iframe src before it appears to a visitor. So here's the order of things that need to happen:

  1. Page loads with all the crucial things for a visitor to see (CSS, text, images, etc.)
  2. Delay the load of the iframes about 5 seconds, to make sure the whole page loads, and the iframes don't slow down the loading time (could use setTimeout?)
  3. Append a bunch of parameters to the iframe src via JavaScript
  4. Then allow the iframe to appear on the page

For the sake of context, here's the website: http://meetingtomorrow.com/ (the iframe is actually a form that appears after you click the blue "Request a Quote" sidetab). There are also often 2 other iframes that appear on the page: an exit intent form and another quote form.

Here's how we're currently initiating the function to append parameters to the iframe src on the site:

<body onload="populateHiddenFields(document.forms['ga-tracking-form'])">

And here's how we're currently appending the parameters to the 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; 

One final piece of key information. This is the actual iframe code:

<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>

Part of the difficulty here is that the iframe src itself is using a PHP function to dynamically populate the first part of the URL. It's a WordPress site, so it's pulling in the permalink (URL of the current page). Then after that permalink, the rest of the parameters are appended to the URL via JavaScript. Hopefully that all makes sense.

Any thoughts or suggestions on how to do this (steps #1-4 above) would be much appreciated! Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
    • ¥15 C# datagridview 单元格显示进度及值
    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配