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 9181203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:13:54+00:00 2026-06-17T18:13:54+00:00

Basically, if the URL/ window.location contains absolutely any variable whatsoever (past domain.com/, of course),

  • 0

Basically, if the URL/window.location contains absolutely any variable whatsoever (past domain.com/, of course), I’d like javascript to execute something.

Currently, I have the following jQuery code which only executes when window.location contains the exact wording “#hash”, but as stated before I’d like to expand the functionality for all variables.

Edit: Sorry, to clarify, by variable I mean any one of the following examples:

  • domain.com/#hash
  • domain.com/#hash2
  • domain.com/sub/folder
  • domain.com/textwithoutahash

Also, if someone knows how to do this in basic Javascript and without the need for the jQuery library, that would be an added bonus!

$(function() {
    if ( window.location.href.indexOf('#hash') > -1 ) {
        myfunctionhere;
    }
});
  • 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-06-17T18:13:55+00:00Added an answer on June 17, 2026 at 6:13 pm

    See update at end re your clarification

    Put the script at the end of the page, just before the closing </body>, and:

    If by “variable” you mean a document fragment identifier (“hash”), then:

    <script>
    if (location.hash) {
        callYourFunction();
    }
    </script>
    

    If by “variable” you mean a query string, then

    <script>
    if (location.search) {
        callYourFunction();
    }
    </script>
    

    If by “variable” you mean a resource name, e.g., not http://domain.com but http://domain.com/page, then:

    <script>
    if (location.pathname && location.pathname !== "/") {
        callYourFunction();
    }
    </script>
    

    More on the location object on MDN.


    Re your clarification:

    Edit: Sorry, to clarify, by variable I mean any one of the following examples:

    Those examples come down to having either hash or pathname or both, so:

    <script>
    if ((location.pathname && location.pathname !== "/") || location.hash) {
        callYourFunction();
    }
    </script>
    

    …and of course, if you also wanted to handle http://domain.com?foo=bar, then add in search as well:

    <script>
    if ((location.pathname && location.pathname !== "/") ||
        location.search ||
        location.hash) {
    
        callYourFunction();
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So basically i want run the code only if url looks like this: www.example.com/#page
Basically, this is what I currently use in an included file: $sites[0]['url'] = http://example0.com;
I am currently using: $(function () { var url = window.location.pathname, urlRegExp = new
I'd like to JavaScript, or JQuery (or any plug in actually) to force the
Here is my problem: window.location.href = (X(1)S( + @Session.SessionID + ))/Cart/AddToCart?productID= + @Model.ProductID; Basically
Basically url escapes a string except uses '+' instead of '%20' for spaces.
What I am trying to do is basically set the URL to take you
Basically I want to check what url the user is on and compare it
basically need to change the value that - admin_url() returns any idea?
Basically, I have multiple URL's stored in a MySQL table. I want to pull

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.