【问题标题】:src loading too fastsrc 加载太快
【发布时间】:2018-09-28 20:40:55
【问题描述】:

我有一个 Wix 网站,我在页面上使用 Google Maps 自动填写表单来获取地址并将其传递给“wix 存储”,它允许变量在用户“会话”中浮动,然后我拉出那个 var并将其推送到一个 HTML 框,其中我有一个小部件,该小部件使用 src 为我提供该小部件的值,我将把该小部件称为 avm 小部件。我的问题是 avm 小部件试图太快地计算 home 的值,因此页面代码没有时间将地址发送到 HTML 和 HTML 将其传递给小部件。我知道 wix 不是一个很多人都会在其中乱用代码的平台。我已经尝试了几乎所有我能想到的东西,但一切都行不通。

这是我整理的代码。

<script>
  var q;

  function get_adress() {
    //gets the adress from the page code
    window.onmessage = (event) => {
      q = event.data;
    }
    return window.q;
  }

  var adress = get_adress();
  var rprAvmWidgetOptions = {
    //this is the var that the rpr widget needs 
    Token: "742980EF-52EE-46F2-AEFB-B2D29D42AB45",
    Query: adress,
    CoBrandCode: "btso48",
    ShowRprLinks: false
  }

</script>
<script language="JavaScript">
  //This was my best shot at a script that could hold the loading of the src so that I could by time for my code to get the var.
  function helper() {

    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = '//www.narrpr.com/widgets/avm-widget/widget.ashx/script';
    head.appendChild(script);
  }

</script>

这是小部件的正常代码。 Query 是我需要替换的。

<script>
  var rprAvmWidgetOptions = {
    Token: "742980EF-52EE-46F2-AEFB-B2D29D42AB45",
    Query: "3911 E Douglas Loop, Gilbert, AZ 85234",
    CoBrandCode: "btso48",
    ShowRprLinks: false
  }
</script>
<script src="//www.narrpr.com/widgets/avm-widget/widget.ashx/script">        
</script>

这是我的 jquery wix 称之为“页面代码”

      // For full API documentation, including code examples, visit                 
http://wix.to/94BuAAs
import wixData from "wix-data"; // activates wix-data
import {session} from 'wix-storage'; // activates wix-storage
$w.onReady(function () {

        let start = session.getItem('1',start);// gets the adress from storage
   setTimeout(
  function() 
  {
  messageSendButton_onClick(start); // waits for html box to load then sneds the adress
  }, 1000);
});
export function messageSendButton_onClick(start) {
  // send message to the HTML Component
  $w('#html1').postMessage(start);
}

【问题讨论】:

  • get_address 不会返回地址,因为它是异步的。只需使用 q 变量。您还可以控制 wix 小部件的加载时间吗?
  • 不,我不这么认为。 q 不会因为范围问题而停止吗?

标签: javascript html src velo


【解决方案1】:

我不擅长解释事情,但我会建议一种方法。

页面代码

 import wixData from "wix-data"; // activates wix-data
 import {session} from 'wix-storage'; // activates wix-storage
 $w.onReady(function () {
    let start = session.getItem('1',start);// gets the adress from storage
    $w("#htmlbox").postMessage({address : start}); }); // send address to wix html box container
 });

页面脚本

 <script>
   window.onmessage = (event) => {
    if (event.data) {
        let _data = event.data;
        let address = _data.address; //get the address
    }
    var rprAvmWidgetOptions = {
        //this is the var that the rpr widget needs 
        Token: "742980EF-52EE-46F2-AEFB-B2D29D42AB45",
        Query: adress,
        CoBrandCode: "btso48",
        ShowRprLinks: false
    }
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = '//www.narrpr.com/widgets/avm-widget/widget.ashx/script';
    head.appendChild(script);
  }
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    相关资源
    最近更新 更多