HTML b页面如何判断a页面

我在a页面点击一个按钮到b页面,b页面里如何判断是不是从a页面的按钮点进来的。😔

A.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <!-- 方式一 -->
        <button><a href="B.html?pageType=a">去b页面</a></button>
        <!-- 方式二 -->
        <button><a onclick="jump()">去b页面</a></button>
        <script>
            function jump() {
                localStorage.setItem('pageType', 'a')
                location.href = 'B.html';
            }
        </script>
    </body>
</html>


B.html


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        BB
        <script>
            // 方式一接收
            var url = location.href
            var pageType = url.indexOf('=') !== -1 ? url.split('=')[1] : null;
            alert(pageType + '页面过来的');
            // 方式二接收
            // var pageType = localStorage.getItem('pageType');
            // alert(pageType + '页面过来的')
        </script>
    </body>
</html>


跳转链接带参数 cookie等都行

用这个可以获取到document.referrer

从a跳转过来可以携带一个url 里type="a"然后判断就行