简体   繁体   English

src加载速度太快

[英]src loading too fast

I have a Wix site and I am using a Google Maps auto fill form on a page to get an address and pass it to "wix storage" which allows variables to float in a users "session", then I pull that var and push it to a HTML box where I have a widget that uses an src to give me the value of that home that widget I am going to refer to as the avm widget. 我有一个Wix网站,我在页面上使用Google Maps自动填充表格来获取地址并将其传递给“ wix存储”,该存储允许变量在用户“会话”中浮动,然后拉出var并将其推送到HTML框,其中有一个小部件,该小部件使用src为我提供该小部件的值,该小部件将被我称为avm小部件。 My problem is that the avm widget tries to calculate the value of the home too fast and so the page code does not have time to send the address to the HTML and the HTML to pass it to the widget. 我的问题是avm小部件尝试过快地计算房屋的价值,因此页面代码没有时间将地址发送给HTML,而HTML没有时间将其传递给小部件。 I understand that wix is not a platform that very many people mess with code in. I have tried just about everything I can think of and it all doesn't work. 我了解到wix并不是一个很多人都将代码弄乱的平台。我已经尝试了几乎所有我能想到的东西,但一切都不起作用。

This is the code I put together. 这是我编写的代码。

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

This is the normal code for the widget. 这是小部件的常规代码。 The Query is what I need to replace. 查询是我需要替换的。

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

This is my jquery wix calls it "page code" 这是我的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);
}

I am not good in explaining things but I will suggest an approach. 我不擅长解释事物,但我会建议一种方法。

PageCode 页面代码

 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
 });

Page script 页面脚本

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM