I have some few lines of codes which I want to run after page reload.
function showServicesList(){
location.reload();
/*
* Statement1
* Statement2
* Statement3
* Statement4
*/
}
Page is refreshing, but the statement below after location.reload
doesn't execute. Any help in this ?
I have some few lines of codes which I want to run after page reload.
function showServicesList(){
location.reload();
/*
* Statement1
* Statement2
* Statement3
* Statement4
*/
}
Page is refreshing, but the statement below after location.reload
doesn't execute. Any help in this ?
-
2
location.reload()
will immediately reload the page as if you had reloaded/refreshed it manually. Any context is lost and you're script execution is halted never making it to any other statement. – phuzi Commented May 21, 2014 at 14:19 - Do you only want to run the rest of the code after the reload or would it be ok to run it on first load? – phuzi Commented May 21, 2014 at 14:32
- I want to run the rest of the code after reload. – Sariban D'Cl Commented May 21, 2014 at 14:38
1 Answer
Reset to default 7Well. If you reload your page, any JavaScript is stopped and reloaded too. If you want your code to run AFTER the page is reloaded you could add a hash.
window.location.hash = "triggerReloadCode";
window.location.reload();
if (window.location.hash.substr(1) == "triggerReloadCode") {
window.location.hash = "";
/* Statements */
}
I don't know if that's best practice, but I would trigger it like this.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745300453a4621404.html
评论列表(0条)