Skip to main content
Question

Code Page execution

  • May 22, 2020
  • 0 replies
  • 66 views

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
This topic has been closed for replies.

  • Registered
  • May 22, 2020
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
------------------------------

  • Registered
  • September 6, 2022
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/?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/
?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
------------------------------

Forum|alt.badge.img+5
  • Registered
  • September 7, 2022
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
------------------------------