Hash in url with JS plugin

Asked

Viewed 126 times

0

I wonder if anyone knows any plug-in or script that picks up the url hash. But that is usual in all browsers. Take more than one hash per url. I know there are several examples on the Internet, but I’m afraid it won’t work on all browsers. So I would like an indication of a 100% usual script with the details given above..

  • 1

    It would be interesting to describe better what you want to do to understand what you need.

  • So Sergio, I’d like to take the URL: ex: tag? #1354#maria. Get these Hashs, but something that is compatible with both old and current browsers. Is there any plugin?

1 answer

0

If this parameter is in query string I use this function and works in IE, Chrome and Mozilla.

 function getQueryString(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? null : decodeURIComponent(results[1].replace(/\+/g, " "));
};

To use just call the query string the method will return the value.

Example

URL: http://localhost/? hash=asdf01215df

       <script type="text/javascript">
           var queryString = getQueryString("hash");
           alert(queryString); // irá imprimir asdf01215df
      </script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.