Javascript - 出于设计原因添加锚点
我有一个小小的 JS 问题: 如果用户访问特殊网站http://www.test.de
,出于设计原因,我想自动向该网址添加锚点 ->结果http://www.test.de/#welcome
。
10秒后我想将锚点更改为 http://www.test.de/#thankyou
这在某种程度上是可能的吗?也许与 window.location 一起?
非常感谢您的帮助!
i have a tiny JS problem:
If a user visits a special site http://www.test.de
i would like to automatically add an anchor to that url for design reasons -> result http://www.test.de/#welcome
.
After 10 seconds i would like to change the anchor to http://www.test.de/#thankyou
Is this possible in some way? Maybe with window.location?
big thx for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在此处使用
window.location.hash
You could use
window.location.hash
hereMDC
window.onload()
文档MDC
window.location.hash
文档MDC
window.onload()
docsMDC
window.location.hash
docs您问题的第一部分 - 将
www.test.de
重新映射到www.test.de/#welcome
可以使用 URL 重写来完成。请参阅 Apache 安装的 mod_rewrite 或 urlrewrite for IIS.net第二个可以轻松地使用 JavaScript 计时器和 window.location 完成,正如您所建议的。
尽管我会从用户体验的角度质疑这种方法。如果您实际上指的是文档正文中的特定锚点,那么用户可能会沮丧地发现他的屏幕在 10 秒后跳转到页面的新部分。如果没有相应的锚点,那就很奇怪(尽管不一定是坏事)。
The first part of your question - remapping
www.test.de
towww.test.de/#welcome
can be done using URL rewriting. See mod_rewrite for Apache installations or urlrewrite for IIS.netThe second could easily be done using a JavaScript timer and window.location as you have suggested.
Although I would question this approach from a user experience perspective. If you are actually referring to specific anchors within the document body, then the user might be dismayed to find his screen jumping to a new part of the page after 10 seconds. If there are no corresponding anchors, then it's just odd (though not necessarily bad).