D
D
Dmitry Zhukov2018-01-28 08:03:52
JavaScript
Dmitry Zhukov, 2018-01-28 08:03:52

How to reload a script without refreshing the entire page?

The script of the callback ordering service (envybox.io) is connected on the page. The page has the ability to select your region, each region has its own id, which is recorded in cookies. The callback service, depending on the ID in the cookie, substitutes the number of a specific manager answering the call. (Native geotargeting in the service does not work well, so I tied it to site cookies). But the problem is that after selecting the city (and overwriting the value in the cookie), you need to completely refresh the page location.reload();so that the callback widget picks up the changed value. How can you reload a widget without refreshing the entire page?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly Zharov, 2018-01-28
@SeaBreeze876

you can create and place a script tag in the DOM

function reloadScript(url) {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = url;
    document.documentElement.appendChild(script);
}
reloadScript('url to reload');

A
Anar, 2018-02-20
@Anarmus

How is the script initialized? Just put a tag <script>on the page and that's it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question