Hi all, I’m not familiar with HTML, javascript, or coding in general but I’ve been managing to struggle through this process from looking at all the helpful forum posts. That being said, I’m currently really stuck.
Here’s what I’m trying to do:
-
I’m making a website to list different available classes. I’m using dynamic pages, repeaters, and a dataset to contain all the information.
-
For each individual class, I will have a unique javascript code which directs to a Shopify widget as a “add to cart” button on the screen. I want users to buy via this shopify widget. Because this code would change per-class, the easiest thing would be if I could paste that javascript into one of the fields on the dataset, then link the iFrame to read that code, depending which class page is currently loaded.
I’ll show below the code I have so far. I’ve gotten it to semi-work (I’m able to dynamically grab the textfield that contains the javascript (shopifyButton), but I’ve been having a lot of trouble getting the iFrame to read the ‘post message’. ((right now my console.logs will output that the data being read from getCurrentItem() is what i want, but I’m having issues getting the iFrame to read and display it.
var htmltxt;
$w.onReady( () => {
$w("#teamDataset").onReady( () => {
let itemObj = $w("#teamDataset").getCurrentItem();
htmltxt = String(itemObj.shopifyButton);
console.log(typeof htmltxt);
//put this here to make sure htmltxt was, in fact, a string
} );
} );
export function iHTMLButton_message(event) {
// Add your code for this event here:
$w("#iHTMLButton").postMessage($w(htmltxt).value);
console.log(htmltxt)
}
Again, I’m not really familiar with javascript, I’d like to say I have a pretty solid head on my shoulders, but this is a bit out of my understanding. Any help would be appreciated!