简体   繁体   English

是否可以从网址中删除#?

[英]Is it possible to remove # from url?

I want to scroll down to the product section on my page. 我想向下滚动到页面上的“产品”部分。 I use www.example.com/#product and it works correctly scrolled down to the product section. 我使用www.example.com/#product,它可以正常滚动到产品部分。 If I use js it will scroll down to the product section too, but url is not included /product. 如果我使用js,它也会向下滚动到product部分,但/ product不包含url。

Can I scroll down to the product section without # like example.com/product? 是否可以向下滚动到没有#的产品部分,例如example.com/product?

.htaccess image .htaccess图片

link image 连结图片

In javascript 在JavaScript中

const getURLParamValue = (query) => {
    let t = document.URL,
        a = query,
        params = i = j = k = null,
        arr = [];
    params = t.split('?')[1].split('&');
    l = params.length;
    for (i = 0; i < l; i++) {
        k = params[i].split('=');
        arr[k[0]] = k[1].replace('#','');
    }
    return arr[a];
}

Have you tried using this? 你试过用这个吗?

if(section === 'products'){
    $('html, body').animate({
       scrollTop: $("#products").offset().top
    }, 500);
}

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

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