如何防止片段标识符显示在url中

编程入门 行业动态 更新时间:2024-10-23 09:28:27
本文介绍了如何防止片段标识符显示在url中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这样的链接

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

点击链接后,网址将从

http:/domain

domain#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.

jsfiddle/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中

本文发布于:2023-10-12 23:27:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486189.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标识符   片段   如何防止   url

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!