-3

I am trying to pass a variable through the URL.

Here is an example URL : http://www.example.com?activeTab=#myProfile

The #myProfile is supposed to be a jQuery selector, but the variable activeTab ends up being equal to nothing. The hashtag ends up cutting off the variable for some reason.

If I were to remove the hashtag, the variable ends up being 'myProfile'. So the issue is certainly the hashtag.

Thanks!

Wyatt
  • 445
  • 3
  • 12
  • You need to encode it https://www.w3schools.com/tags/ref_urlencode.asp – litelite Jul 26 '17 at 14:57
  • # in URLs are used for anchors – Philipp Sander Jul 26 '17 at 14:58
  • 1
    Your code is missing a [mcve]. – Quentin Jul 26 '17 at 14:58
  • @Quentin False. I gave an example URL. – Wyatt Jul 26 '17 at 14:59
  • A hashtag is a means of indicating that a term, in plain text, should be hyperlinked to a search engine on social media networks. It gets the name because it it uses a hash character to prefix it. Please don’t confuse other uses of the hash character with hashtags. What you are talking about is a **URL [Fragment Identifier](https://tools.ietf.org/html/rfc3986#section-3.5)** – Quentin Jul 26 '17 at 14:59
  • 3
    @Wyatt — Then you started talking about variables. URLs don't have variables. Presumably you have some programming language involved. That code is doing something with the URL. We can't tell what because your code is missing. You mentioned jQuery, so presumably you are talking about client side JavaScript … but how it gets from the URL to your code I've no idea. – Quentin Jul 26 '17 at 15:00
  • @Quentin Of course URLs have variables. They follow the question mark, correct? – Wyatt Jul 26 '17 at 15:01
  • @Quentin Oh, I see your confusion. I am using PHP. They are $_GET variables. – Wyatt Jul 26 '17 at 15:02
  • Duplicate: https://stackoverflow.com/questions/36042694/how-to-get-hash-value-in-query-string – Quentin Jul 26 '17 at 15:03

1 Answers1

-1

You write your jquery code to prepend # in the selector and read value from the param. # has meaning in the URL and thus activeTab=nothing and HTML attempts to look for #myProfile anchor locator on the page

Rikin
  • 5,351
  • 2
  • 15
  • 22