M
M
mletov2015-12-25 23:09:11
JavaScript
mletov, 2015-12-25 23:09:11

Is it possible to track the connection callback of an external script and change the DOM it generates?

Please tell me:
I'm connecting a widget to the site from another resource.

script src="http://another-site.com/widjet.js" event-id="12345"

It generates code like
<div id="some-widjet">Какой-то текст</div>
Well, I don't like the text on their button.
I want to do something like this
...
         $("#some-widjet").html("Новый текст");
          ...

But I can’t understand whether it’s possible to somehow catch this callback, where to insert my code, or not.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Leonovich, 2015-12-26
@mletov

Use $.getScript https://api.jquery.com/jquery.getscript/

$.getScript('http://another-site.com/widjet.js', function() {
    $("#some-widjet").html("Новый текст");
});

You can also do this:
var el = document.createElement('script');

el.src = 'http://another-site.com/widjet.js';
el.onload = function() {
    // Ваша логика, например
    $("#some-widjet").html("Новый текст");
}

document.body.appendChild(el);

V
Valery Serov, 2015-12-26
@DrBronson

Refer to the widget's documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question