I have an external JavaScript to call like this:
<script type="text/javascript" src="https://ndd.com/script.js" data-goal="12345"></script>
According to getScript
, the call will be:
$.getScript("https://ndd.com/script.js", function(data, textStatus, jqxhr) {
console.log(data); // Data returned
console.log(textStatus); // Success
console.log(jqxhr.status); // 200
console.log("Load was performed.");
});
By the way I don't find any information about how to pass the data-goal
parameter.
I can't use the standard way (add the first JavaScript example) in my code, and it needs to be called from a JavaScript file.
Any clue?
EDIT: For information, the Javascript is called but not executed. The only way it works is this one following:
var tagString ='<script type="text/javascript" src="https://ndd.com/script.js" data-goal="12345"></script>';
eval($('').find("script").text());
var range = document.createRange();
range.selectNode(document.getElementsByTagName("BODY")[0]);
var documentFragment = range.createContextualFragment(tagString);
document.body.appendChild(documentFragment);