Skip to content
On this page

Common Questions / Issues

Multiple widgets in one page

When using multiple widgets in a single page only a few minor changes are needed. In the following example code, these are mentioned in the comments.

html
<script lang="js">
    (function (btc, d, i, r, e, c, t) {
        // The code from the "Getting started" page is omitted for readability.
    })
    // In the below line, the value "btcdirect" is changed to "buyWidget".
    (window, document, 'script', 'buyWidget',
        'https://cdn.btcdirect.eu/fiat-to-coin/fiat-to-coin.js'
    );

    // The value of this function call has to match the above change ("buyWidget").
    // Also a new parameter is added for the selector.
    buyWidget('init', { token: 'API_KEY', selector: 'buy-widget' });

    // When adding another widget, in this case the sell widget,
    // the name has to be different to reach each widget separately.
    (function (btc, d, i, r, e, c, t) {
        // The code from the "Getting started" page is omitted for readability.
    })(window, document, 'script', 'sellWidget',
        'https://cdn.btcdirect.eu/coin-to-fiat/coin-to-fiat.js'
    );

    sellWidget('init', { token: 'API_KEY', selector: 'sell-widget' });
</script>

Now we have to widget calls in the page they need individual target elements in order to display them. These have classes added to them that match the selector-values in the above code example.

html
<div class="widgets">
    <fiat-to-coin-widget name="f2c" selector="f2c-widget"  />
    <coin-to-fiat-widget name="c2f" selector="c2f-widget" />
</div>

<style>
    .widgets {
        display: grid;
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    @media screen and (min-width: 700px) {
        .widgets {
            grid-template-columns: 1fr 1fr;
        }
        .widgets .btcdirect-widget-container {
            width: 100%;
        }
    }
</style>

If everything is done correctly, it should result in the following:

CORS Errors

When calls from the widget result in CORS-related errors, this is usually caused by the containing website’s referrer policy. Make sure that the referrer header is present in the call headers and it’s not empty.

Sometimes this is caused by external packages such as “helmet” and “nuxt-helmet”. In these cases the referrer can be enabled in the package settings.

Is there support for iFrames?

We do not support iFrames, nor do we plan to.

Why don't you support iFrames?

Our widgets are designed to be embedded directly into the website. We don't offer iFrames for our widget/unified checkout due to security concerns and the need for a fully controlled, secure payment environment.

Made with ❤ by BTC Direct