Javascript window.location搜索"#"永远不会返回true

ens*_*are 2 javascript jquery javascript-events

我正在尝试设置一个重定向器,以便当我的AJAX函数更改URI的哈希部分时,如果链接被复制和粘贴,该链接仍然可以直接访问.我目前的职能如下; 但是,它总是返回false!

    //If a hash is found, redirect it
    var current_uri = String(window.location);

    if (current_uri.search('/\#/') != -1) {
            var current_uri_array = current_uri.split('#');
            window.location = current_uri[1];
    }
Run Code Online (Sandbox Code Playgroud)

如何更改代码以使其工作?有没有更好的方法呢?谢谢你的帮助.

代码更新为:

if (window.location.hash) {
    window.location = window.location.hash.substring(1);
Run Code Online (Sandbox Code Playgroud)

}

哪个有效.

Tom*_*ana 5

尝试window.location.hash直接使用;)