简体   繁体   中英

How to make Javascript Reload without refresh

I would like to know if it is possible to reload the Javascript in a page without refreshing the whole thing, thus losing the edited Css elements.

My scenario:

I'm editing an highly dynamic slider, and every element has to be carefully positioned. I only have one element into the hypothetical sliders's array, and once the animation for that single slider ends, there's no way to see the changes I've made taking action.

I know I can hardcode into the html another slider, so they'll keep going forever, yet I'd be more intrigued in some sort of console solution.

Any clue?

You could load a new script with a function, let's say it's called loadJS:

function loadJS(script)
{
    var docHeadObj = document.getElementsByTagName("head")[0];
    var dynamicScript = document.createElement("script");
    dynamicScript.type = "text/javascript";
    dynamicScript.src = scriptName;
    docHeadObj.appendChild(newScript);
}

So whenever you want to 'reload' the script, you can execute the function, for example: loadJS('file.js');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM