【问题标题】:Check if current URL contains hash [duplicate]检查当前 URL 是否包含哈希 [重复]
【发布时间】:2018-02-18 07:34:56
【问题描述】:

使用 Javascript 如何检查当前 URL 是否包含哈希?

在测试页面中我想添加一个 Javascript 代码来打印:

<p>yes, there is a hash here</p>

如果存在哈希(当前页面http://www.example.com/test/#abc)或:

<p>no, there is no hash here</p> 

如果哈希不存在(当前页面http://www.example.com/test/)。

【问题讨论】:

    标签: javascript if-statement


    【解决方案1】:

    很简单

    if(window.location.hash) {
       //# in URL
    } 
    

    【讨论】:

    • 我们不需要另一个回答这个问题。
    猜你喜欢
    • 2017-04-28
    • 2013-11-22
    • 1970-01-01
    • 2017-04-13
    • 1970-01-01
    • 2014-04-06
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多