admin管理员组文章数量:1419240
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.
本文标签: javascriptHow to run the statement after reloading the page in jqueryStack Overflow
版权声明:本文标题:javascript - How to run the statement after reloading the page in jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745300453a2652340.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论