如何在JavaScript中重新加载页面后显示警告? [英] How to show an alert after reloading the page in JavaScript?

查看:91
本文介绍了如何在JavaScript中重新加载页面后显示警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在页面重新加载后制作警报框,但它不起作用。

请更正我的代码并告诉我原因?

I am trying to make alert box after page reloaded, but it doesn't work.
Please correct my code and tell me why?

$("button").click(function(){
    window.location.reload();
    alert("Hello world");
});


推荐答案

您可以使用 sessionStorage

You can use sessionStorage:

$( "button" ).click( function () {
        sessionStorage.reloadAfterPageLoad = true;
        window.location.reload();
    } 
);

$( function () {
        if ( sessionStorage.reloadAfterPageLoad ) {
            alert( "Hello world" );
            sessionStorage.reloadAfterPageLoad = false;
        }
    } 
);

这篇关于如何在JavaScript中重新加载页面后显示警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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