简体   繁体   English

如何从链接隐藏URL?

[英]How to hide URL from link?

I'm having a little problem and I am a bit of a noob to coding but can do HTML ok-ish. 我有一个小问题,我对编码有点儿菜鸟,但可以做HTML。 So ok, How do I remove the # from my url, currently it is /#contact but I just want /contact. 好的,如何从网址中删除#,目前它是/#contact,但我只想/ contact。 There is an option in my custom.js to hide the hash but when I do that, the /{pagename} disappears and all I see in the address bar is my domain. 我的custom.js中有一个隐藏哈希的选项,但是当我这样做时,/ {pagename}消失了,我在地址栏中看到的只是我的域名。 It's a landing page with javascript so they aren't pages as such, it just scrolls down the page to the correct section. 这是带有javascript的登录页面,因此它们不是此类页面,它只是将页面向下滚动到正确的部分。

So I have seen somewhere that I need to add return false to something like click event? 因此,我已经看到需要在某些地方添加return false到click事件之类的东西吗? I can't find this enywhere in any of the js files. 我在任何js文件中都找不到这个地方。 The other thing was the window.location.href but can't find that either. 另一件事是window.location.href,但也找不到。

Here is the only thing I've found in all of my js files. 这是我所有js文件中唯一找到的东西。

jQuery(document).ready(function() {

    /* navigation local scroll  ----------- */
        jQuery("ul.nav").localScroll({ 
                event:'click', 
                hash:true,
                easing:'easeInQuad', 
                duration:1000,
                offset:-45
        });

So in essence, what do I need to do to remove the hash. 所以从本质上讲,我需要怎么做才能删除哈希。

First, some explanations: #contact at the end of your URL, means that your browser will try to reach an element in your HTML which have the id attribute equals to "contact". 首先,一些解释:URL末尾的#contact ,表示浏览器将尝试到达HTML中id属性等于“ contact”的元素。

Next, your solutions: 接下来,您的解决方案:

You won't be able to only remove the hash before content with only client technology (ie: javascript), you need to go through your server to rewrite your URL (eg: using Apache Rewrite module). 仅使用客户端技术(即javascript),您将无法仅在content之前删除哈希,而您需要遍历服务器以重写URL(例如:使用Apache Rewrite模块)。

But indeed, what you could do, if you don't mind about losing content in your URL, is to prevent the URL from changing when you scroll to this element in your javascript, using event.preventDefault(); 但是确实,如果您不介意丢失URL中的content ,则可以做的是使用event.preventDefault();防止在滚动到javascript中的该元素时URL发生更改event.preventDefault(); ... or with your localScroll stuff, it can be done by setting the hash option to false : ...或使用您的localScroll东西,可以通过将hash选项设置为false来完成:

jQuery("ul.nav").localScroll({ 
                event:'click', 
                hash:false, // oh yeah
                easing:'easeInQuad', 
                duration:1000,
                offset:-45
        });

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

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