function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
// example
<script src="http://localhost:8080/static/test.js?u=http://localhost:8080/api/get"></script>
var api = "";
var scripts = document.getElementsByTagName("script");
if (scripts && scripts.length > 0) {
for (let i = 0; i < scripts.length; i++) {
if (scripts[i].src.indexOf("ictr") !== -1) {
api = getParameterByName("u", scripts[i].src);
}
}
}
console.log(api) // http://localhost:8080/api/get