0

I need load piece of content into my div, I need execute the script I have in remote div, for example I have

<div id="thisIsRemoteContent">
<script src="blabla.js"></script>
</div>

in the remote-content.html

Now I need load it with script to my page

$('.mydiv').load("remote-content.html #thisIsRemoteContent");

In jquery API documentation was written that if I load piece of contet, then the script will not be executed.

When calling .load() using a URL without a suffixed selector expression, the content is passed to .html() prior to scripts being removed. This executes the script blocks before they are discarded. If .load() is called with a selector expression appended to the URL, however, the scripts are stripped out prior to the DOM being updated, and thus are not executed.

However, how can I load it with script?

1

1 Answer 1

1

cant you do 2 calls?

    $('.mydiv').load("remote-content.html");
    $.getScript('blabla.js');

you can manipulate with the script name so the remote content will know what its name and then put it in some attribute inside the remote-content.html like:

<div>my remote content</div>
<span scriptname="blabla.js"></span>

so then:

    $('.mydiv').load("remote-content.html");
    $.getScript($('span[scriptname]').attr('scriptname'));
Sign up to request clarification or add additional context in comments.

2 Comments

thank you for answer, I can't do anything with script, it is comming from admin panel, user is just putting the script like this '<script type="text/javascript" charset="utf-8" src="api-maps.yandex.ru/services/constructor/1.0/js/…>' I can manipulate only with its parent-wrapper
i dont know then. its a big issue all the XSS protections makes the work much harder for us ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.