Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6895955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:58:28+00:00 2026-05-27T06:58:28+00:00

I am adding a Search feature, and if the user is on the search

  • 0

I am adding a Search feature, and if the user is on the search results and they refresh the page I want it to stay at that search. I already put the search query into the URL, but I don’t know how to retrieve it. It will most likely require a regexp so anyone that is experienced with regexp, please help.

screenshot w/ description

Here is how I put it into the URL:

function trimspace(str) {
    str = str.replace(/ +(?= )/g, '');
    return str;
}
function searchMail() {
    var query = trimspace($('#search_input').val());
    if (query == '' || !query || query == null) {
        $('#search_input').focus();
    }
    else {
        window.location.hash = '#!/search/' + query;
        $('#loader').show();
        $.get('tools.php?type=search', { q: query }, function(data, textStatus) {
            $('#loader').hide();
            if (textStatus == 'success') {
                hideAllTabs();
                $('#search_results').html(data).show();
                document.title = "Search results - WeeBuild Mail";
            }
            else {
                alertBox('Search failed. Please try again in a few minutes.', 2500);
            }
        });
    }
}

And besides just retreiving the query I need to be able to detect if the hash is #!/search/query.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:58:28+00:00Added an answer on May 27, 2026 at 6:58 am

    Detect if query is #!/search/query:

    location.hash==='#!/search/query'
    

    Finding out about the query parts assuming the query is #!/search/query:

    var parts = location.hash.split('/');
    

    parts[0] is #!. parts[1] is search and parts[2] is test. Doing with the parts want you want should now be trivial enough.

    In response to the comments:

    function getPartAndRemainder(){
        var parts = location.hash.split('/');
        if(parts[0]!=='#!' || parts.length<2){
            // Value after # does not follow the expected pattern #!/part/any_parameters
            throw new Error('Cannot parse application part.');
        }
        return {
            // Contains the part of your application (word after first slash after #)
            part: parts[1],
            // Contains everything after second slash after # or the empty string
            remainder: location.hash.substring(
                // Length of #! (or whatever somebody might use instead)
                parts[0].length
                // Length of first slash
                +1
                // Length of your application part's name
                +parts[1].length
                // Length of the second slash
                +1)
        };
    }
    

    The function gives back an object that contains the part of your application at the key part and the remainder key will contain the rest. So, if your URI would be something#!/search/test the function would return {part:'search', remainder:'test'}.
    In case the URI can’t be parsed, you’ll get an error and you should then use a sensible default instead.

    You would use the method as follows whenever the hash changes or at some other event (point in time) where you are interested in the hash value:

    try {
        var hashValue = getPartAndRemainder();
        if(hashValue.part==='search'){
            var query = hashValue.remainder;
            alert('You searched: '+query)
        }
        if(hashValue.part==='inbox'){
            alert('You are in inbox, now');
        }
    } catch(e){
        // It was not possible to parse the value after the # from URI according to our expected pattern.
        alert('No idea what to do with: '+location.hash);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when i search for adding a system call, i get many articles but they
Mac OSX Finder has a search feature that darkens everything but the part that
I'm adding a SDE feature class into ArcMap and before it adds in I
I'm adding a new feature to my user module for my CMS and I've
I am adding a sort by option to my search page. I am using
adding the words AND, OR, NOT to a search query raises an error like
I want to build site with a search form on LEFT and RESULTS in
I have a CMS that I am adding Site Search functionality. The application uses
How do you compute the average height of a binary search tree when adding
Adding more than one child to a WPF StatusBar results in poor layout with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.