I've been doing some testing with creating blobs and referencing them for user generated scripts because it makes debugging a lot easier, but I've recently found that while this solution has been very helpful in Firefox, it does not work in Chrome or Safari.
function includeScript(withQuery, script) {
var file = new Blob([script], {
type: "text/javascript"
});
var url = URL.createObjectURL(file);
if (withQuery == true)
url += "?test=hi";
var addMe = document.createElement("script");
addMe.src = url;
addMe.type = "text/javascript";
document.head.appendChild(addMe);
}
function tryIt(withQuery) {
includeScript(withQuery, "alert('hey');");
}
<button onclick="tryIt(false)">Try It Without Query</button>
<button onclick="tryIt(true)">Try It With Query</button>
How can I get blobs to work with query strings in Safari and Chrome the same way they do in Firefox?