简体   繁体   中英

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

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"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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