通过 JS 自动隐藏指定 DIV

<!-- 将需要隐藏的DIV设置一个ID -->
<div class="header" id="header">
    <div class="logo" id="logo">
        <a href="<%linkurl("index")%>">
            <img src="<%templateskin%>/images/logo.png" width="55px" height="auto" />
        </a>
    </div>
    <div class="title">
        这是一个需要隐藏的 header!
    </div>
</div>


<!-- 通过识别链接参数来隐藏页头,链接参数包含 platform=szghapp 则隐藏 header -->
<script>
    // 获取当前页面的 URL
    const urlParams = new URLSearchParams(window.location.search);

    // 获取名为 "platform" 的链接参数
    const hideParam = urlParams.get('platform');

    // 判断是否需要隐藏指定的 div
    if (hideParam == 'szghapp') {
      const div = document.getElementById('header');
      div.style.display = 'none';
    }
</script>

<!-- 通过识别链接参数来隐藏页头,通过识别链接参数来隐藏页头,链接参数包含 platform=szghapp 则隐藏 header -->
<!-- 写入localStorage,后续的页面不带参数也可自动隐藏 -->
<script>
    // 从 localStorage 中获取 platform 参数
    var platForm = localStorage.getItem('platform');
    if (platForm == null) {
        // 从当前页面的 URL 获取 platform 参数
        const urlParams = new URLSearchParams(window.location.search);
        platForm = urlParams.get('platform');
    } 
    // 判断是否需要隐藏指定的 div
    if (platForm == 'szghapp') {
      const div = document.getElementById('header');
      div.style.display = 'none';
      localStorage.setItem('platform', platForm);
    }
</script>

<!-- 通过识别user-agent参数来隐藏页头,user-agent 包含 szghapp 则隐藏 header -->
<script>
    const userAgent = navigator.userAgent;
    if (userAgent.includes('szghapp')) {
      const div = document.getElementById('header');
      div.style.display = 'none';
    }
</script>