简体   繁体   English

JS,如何理解页面是刷新还是第一次打开?

[英]JS, How can understood page is refreshed or first time opened?

Using javascript possible understood if page is load witch refresh button or F5 key? 如果页面加载巫婆刷新按钮或F5键,使用javascript可能会理解? that is JS can make something like this? 这是JS可以做这样的事情?

            if (/*   page is load wich browser "refresh" button or "F5" key   */) {
                alert("page is refreshed");
            }
            else if (/*    we coming here from other page    */) {
                alert("We coming here from other page");
            }

You can check the document.referrer property, but note that it will be blank both when the page is refreshed and when the user arrived at the page via a bookmark or by typing the URL directly in the browser address bar (and possibly if they have a browser extension blocking referrer information). 您可以检查document.referrer属性,但请注意,这将是空白都刷新页面当,当用户通过书签或直接在浏览器地址栏中输入网址(到达网页和可能,如果他们有浏览器扩展名阻止引用者信息)。 It will normally have a value when the user has clicked a link to get to the page. 当用户点击链接进入页面时,它通常会有一个值。 So it's imperfect, but I don't know that there's anything better without doing server-side stuff. 所以它不完美,但我不知道如果不做服务器端的东西就会有更好的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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