在jquery中重新加载页面后运行代码 [英] Run the codes after reoading the page in jquery

查看:106
本文介绍了在jquery中重新加载页面后运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在刷新页面后运行几行代码。

I have some few lines of codes which I want to run after refreshing the page.

function showServicesList(){
    location.reload();

    /*
    *   Statement1
    *   Statement2
    *   Statement3
    *   Statement4
    */
}   

但页面令人耳目一新,但以下代码未运行..任何帮助..

But page is refreshing but the below codes are not running.. Any help ..

推荐答案

好吧。如果您重新加载页面,任何JavaScript都会被停止并重新加载。如果你希望你的代码在重新加载页面后运行,你可以添加一个哈希值。

Well. 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.

这篇关于在jquery中重新加载页面后运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆