Files
orico-official-website/app/index/view/pc/public/nas_header.html

57 lines
2.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<header class="narsPage-head">
<div class="headcenter">
{eq name=":cookie('think_lang')" value="zh-cn"}
<a href="{:url('/index/topic/nas/index')}">
{else/}
<a>
{/eq}
<img class="logico" style="cursor:pointer;" src="__IMAGES__/logo_nas_{:cookie('think_lang')}.png" />
</a>
{notempty name="header_navigation"}
<nav class="headnav">
{volist name="header_navigation" id="nav" key="idx"}
<a class="navitem {eq name='idx' value='1'}hover{/eq}" href="{$nav.link}" target="{$nav.blank==1?'_blank':'_self'}">
{$nav.name}
</a>
{/volist}
</nav>
{/notempty}
</div>
</header>
<script type="text/javascript">
$(function() {
$('.headnav .navitem').each(function(idx, item) {
var _item = $(item);
_item.removeClass('hover');
if (_item.attr('href') && compareUrls(location.href, _item.get(0).href)) {
_item.addClass('hover').siblings();
}
});
// 比较两个URL是否相等支持只有path的情况并处理有无.html后缀的情况
function compareUrls(url1, url2) {
// 如果输入的是相对路径,添加当前域名
if (!url1.startsWith('http')) {
url1 = window.location.origin + (url1.startsWith('/') ? '' : '/') + url1;
}
if (!url2.startsWith('http')) {
url2 = window.location.origin + (url2.startsWith('/') ? '' : '/') + url2;
}
// 将两个URL转换为URL对象
const urlObj1 = new URL(url1);
const urlObj2 = new URL(url2);
// 获取路径名并移除末尾的斜杠
let path1 = urlObj1.pathname.replace(/\/$/, '');
let path2 = urlObj2.pathname.replace(/\/$/, '');
// 移除.html后缀
path1 = path1.replace(/\.html$/, '');
path2 = path2.replace(/\.html$/, '');
// 比较处理后的路径
return path1 === path2;
}
})
</script>