Script inside FAQ

Hi

I need to insert a script showing some football statistics in the FAQ widget as an answer.
It saves the script but doesn’t show it

4 Likes

Hi there, @Kasper_Skov_Jensen :wave:

The thing is that the Custom JS codes work only upon widget installation, not in preview mode. However, I also see some validation errors there:

Could you please elaborate on your use case and describe how this script should work? Do I get it right that you’d like to pull some statistics from a specific source?

1 Like

Hi Max

Thanks for the reply.

I can’t get it to work on live sites either

The usecase is this: I have created the FAQ widget like this: https://c0c49d93469b4582a18f6ed24c1633bc.elf.site

In this example the questions are headlines about relevant statistics about Premier League.

The answer should be a script showing the table, goal scores etc.

2 Likes

Got it, thanks!

We’ve added this code to the answer HTML section (view Code Editor mode) for the Table question:

<div id="js-statorium-widget-638"></div>

<img style="display: none" src="x" 
onerror='(function(el){ 
    const script = document.createElement("script");
    script.src = "https://statorium.com/components/com_statoriumwidgets/assets/js/widget.js";
    script.type = "text/javascript";
    script.id = "js-statorium-id-638";
    document.body.appendChild(script);
    
    const widgetContainer = document.createElement("div");
    widgetContainer.id = "js-statorium-widget-638";
    document.body.appendChild(widgetContainer);
    
    script.onload = function() {
        const jsStatoriumWidgetClone = Object.assign({}, jsStatoriumWidget);
        jsStatoriumWidgetClone.setOptions({
            targetId: "js-statorium-widget-638",
            widgetID: 638,
        });
        jsStatoriumWidgetClone.render();
    };
})(this);'
/>


If you like the result, please remove your script from the Custom JS section and publish changes :slightly_smiling_face:

1 Like

Hi again

It looks great, but I’m not sure how to do it and replicate it with other statistics from the same provider. Maybe you could write it out, step by step?

1 Like

To identify what values should be changed in the code, we need a code pulling this (new) statistic from your provider. Could you please provide me with it?

Here is anorther one:

<div id="js-statorium-widget-648"></div>

<script>
    (function(doc, tag, id){
        let js = doc.getElementsByTagName(tag)[0];
        if (doc.getElementById(id)) {return;}
        js = doc.createElement(tag); js.id = id;
        js.src = "https://statorium.com/components/com_statoriumwidgets/assets/js/widget.js";
        js.type = "text/javascript";
        doc.body.appendChild(js);
    }(document, 'script', 'js-statorium-id-648'));
    window.addEventListener("load", function() {
        const jsStatoriumWidgetClone = Object.assign({}, jsStatoriumWidget);
        jsStatoriumWidgetClone.setOptions({
            targetId: "js-statorium-widget-648",
            widgetID: 648
        });
        jsStatoriumWidgetClone.render();
    });
</script>

Just a heads up: I have a lot of them :grinning_face_with_smiling_eyes:

1 Like

Here is the code for the new statistics:

<div id="js-statorium-widget-648"></div>

<img style="display: none" src="x" 
onerror='(function(el){ 
    const script = document.createElement("script");
    script.src = "https://statorium.com/components/com_statoriumwidgets/assets/js/widget.js";
    script.type = "text/javascript";
    script.id = "js-statorium-id-648";
    document.body.appendChild(script);
    
    const widgetContainer = document.createElement("div");
    widgetContainer.id = "js-statorium-widget-648";
    document.body.appendChild(widgetContainer);
    
    script.onload = function() {
        const jsStatoriumWidgetClone = Object.assign({}, jsStatoriumWidget);
        jsStatoriumWidgetClone.setOptions({
            targetId: "js-statorium-widget-648",
            widgetID: 648,
        });
        jsStatoriumWidgetClone.render();
    };
})(this);'
/>

The code is the same as in the previous case, we’ve just replaced the number of the table with the statistics (638 was replaced with 648):


Please let me know if this explains things or if you have any questions left :slightly_smiling_face:

1 Like

Thanks for amazing support!

2 Likes

You’re always welcome :wink:

In the meantime, we’d like to invite you to join our new challenge, where you can win 3 FREE months for your subscription. Check the details and participate :slightly_smiling_face: - March Challenge: Share your results with Elfsight & win 3 FREE months!:rocket:

Hi @Max

I just realized that the “answers” in my FAQ widget sometimes doesn’t expand completely first time the “question” is clicked. Is there a way to fix it?

1 Like

Hi @Kasper_Skov_Jensen :wave:

I’ve checked the widget and the expand option is working fine for me:


If the issue still persists on your end, please send me a video screencast of what you see :folded_hands:

Hi Kasper
I’m a big Bournemouth fan, and Fantasy Football player. I’m curious about how the end result looks and where you have put it. Are you happy to share a URL?
Martin

1 Like

@Martin1 Wow, one more football fan here :star_struck:

Nice season for Bournemouth by the way and Kluijvert especially. Can’t forget their game against Arsenal in October (cause I am an Arsenal fan :grin:)

1 Like

Hi Martin

I’m happy to share the link next week, when we are live with the content. :rocket:

Hav a great weekend