-1
I have a <script>
external being added to the page via jQuery com:
$("body").append("<scr"+"ipt src='url_do_script.js'></scr"+"ipt>");
This script adds some elements on the page (some tags). The script works perfectly, but it is asyronous when loading the page, that is, the page loads normally without waiting for what the script will return. But I need to manipulate some tags returned by this .js
as soon as they are available.
The problem is that I haven’t found a way to know when this script has already been fully loaded on the jQuery page.
With pure Javascript I can know by adding the script via document.createElement
and appendChild
. Just make a .onload
:
var e = document.createElement("script");
e.src = "url_do_script.js";
document.body.appendChild(e);
e.onload = function(){
// o script foi totalmente carregado
}
How to do something with the .append
jQuery? I’ve tried other ways .get
, .load
and .ajax
but does not work due to CORS (Cross-origin Resource sharing).
I tried to put a onload="funcao()"
in the <script>
and it didn’t work either.
Any idea how to do this or is there another way using jQuery other than with .append
?
The fact of
onload
does not work, is that the element script does not have this event. When you use withcreateElement
, he is creating an object supporting that event, not necessarily creating the element itself. He has tried it with the getScript? You can also create extend the jquery– Valdeir Psr