JSFiddle - React, Tailwind, and code Playground

by web-nfo.com

HTML

<script src="https://cs.photoprintit.com/web/85000005/assets/85000005/_generic/jquery-1.8.3.min.js"></script>
<a href="#abc" onclick="runWhenAvailable('loadQubitScript',this,function(){loadQubitScript($(this).attr('href'), 'twee');});">Test</a>

JavaScript

// Qubit runWhenAvailable
console.clear();


// Run a function only when it's available
function runWhenAvailable(functionName, object, callback, nextDelay) {
    if(typeof nextDelay == 'undefined') {
        var nextDelay = 100; // Start delay (ms)
    } else {
        nextDelay = nextDelay + Math.round(nextDelay / 3); // Incremental delay for next check
    }
    var functionAvailable = false;
    
    if (
      (functionName == 'loadQubitScript' && typeof loadQubitScript == 'function') ||
      (functionName == 'gaAllowIframeTracking' && typeof gaAllowIframeTracking == 'function') ||
      (functionName == 'gaCallPushEvent' && typeof gaCallPushEvent == 'function')
    ) {
    	// Execute the (callback) function
    	callback.apply(object);
        functionAvailable = true;
    }
    
    if(!functionAvailable) {
        setTimeout(function(){ // Try again in ... ms
            if(typeof console != 'undefined') {
                console.log('function ' + functionName + ' not available, try again in ' + nextDelay + 'ms');
            }
            runWhenAvailable(functionName, object, callback, nextDelay);
        }, nextDelay);
    }
}

function loadQubitScript(a, b) {
    alert(a);
    alert(b);
}