Discussions

 View Only
  • 1.  Code Page execution

    Posted 05-21-2020 22:15
    I have two Code page in that pages I do some quickbase API call and I create a functions inside, the doubt is if its possible to call a function in Page1 from page2 to avoid write the same code in both pages?


    Any idea?

    Thanks


  • 2.  RE: Code Page execution

    Posted 05-22-2020 04:26
    You can use jquery's GetScript to add the code, i.e.
    $.getScript("mydomain.quickbase.com/db/appid?a=dbpage&pagename=my_script.js", function() { alert("Tada, script is loaded"); });


    ------------------------------
    Ben Smith
    ------------------------------



  • 3.  RE: Code Page execution

    Posted 09-06-2022 09:53
    Hey, 

    You can use JS Modules to export/import code between pages.

    JavaScript Modules (w3schools.com)

    You would have to put the URL address of your application, with the table ID and page ID appended in the import function and add type="module" to your script tags in your HTML.

    Code page (HTML):
    <script type="module" src="https://mycompany.quickbase.com/db/[TABLE_ID]?a=dbpage&pageID=[PAGE_ID]"></script>

    Code Page (JS) 1 ():

    export default let myFunction = () => {
            // Some code here 
    }

    Code Page (JS) 2:
     
    import myFunction from "https://mycompany.quickbase.com/db/[TABLE_ID]?a=dbpage&pageID=[PAGE_ID]"
    In theory this should work, however, I haven't tried it myself.
    You could also try adding another script tag to your html pointing to the other JS file.

    ------------------------------
    Luke Stone
    ------------------------------



  • 4.  RE: Code Page execution

    Posted 09-07-2022 17:31
    You can create a third page with only your shared functions and import it with a script tag.
    You can even host that page outside quickbase on any CDN

    ------------------------------
    Simon H
    ------------------------------