如何防止片段标识符显示在url中 [英] How to prevent fragment identifiers from showing in url

查看:193
本文介绍了如何防止片段标识符显示在url中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的链接

    <a href="#login_form">Log in</a>

点击链接后,网址将从

   http:/domain.com

   http://domain.com#login_form

,然后弹出一个登录表单. 但我不希望哈希标签显示在url中.如何使用Java脚本执行此操作?没有用于显示弹出的登录表单的Java脚本.

and a login form pops up. But i do not want hash tag to be displayed in url. How to do this using java script? No java script used to display login form which pops up.

登录表单是这样的.

    <a href="#x" class="overlay" id="login_form"></a>
    <div class="box">
    <h2>LOG IN</h2>
    <form name="login" action="" method="post">
    </form>
    </div>

好.这是JS FIDDLE.请检查.

OK. HERE IS THE JS FIDDLE. PLEASE CHECK.

http://jsfiddle.net/vq24P/1/

推荐答案

它被称为文档片段,不是哈希标签,而是什么.

It's called a document fragment, not a hash tag, but whatevs.

如果您说没有Java脚本用于显示登录表单",我只能假设您使用CSS :target伪类来切换可见性?在这种情况下,您无能为力.该片段必须出现在该元素的URL中.

If, as you say, "no java script [is] used to display login form", I can only assume you're using the CSS :target psuedo-class to toggle visibility? In that case, there's nothing you can do. The fragment MUST be in the URL for that element to show up.

相反,请使用一些JavaScript为您进行切换.像这样:

Instead, use some JavaScript to do the toggling for you. Something like:

<a href="javascript:void(document.getElementById('login_form').style.display = 'block');">Log in</a>

(警告:极端糟糕的例子,但应该可以使一般想法起作用)

(WARNING: Extremely bad example, but it should get the general idea working)

您将需要使用id="login"而不是name="login"

这篇关于如何防止片段标识符显示在url中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆