Reputation: 1509
This isn't the best question ever, but since search engines feel the need to ignore symbols, I have to ask somewhere.
In a link, I'll sometimes see a ?
, such as [link]/file.extension?some_type_of_info
, or even +,&,=, etc ('best example' of what I mean is youtube videos). What are these called and what do they do? A good site would be great to :)
I am mostly interested because I have a site that loads stuff into a page, and currently the way I allow 'bookmarking' a page (or more important to me, being able to go back a 'page') is use hash values to represent my 'page'.
Ultimately I would like to not have the page refresh, which is why hash values are good, but I'd like alternatives if any (not really what hashmarks are meant for, but mostly different browsers seem to treat assigning the hash values in jquery differently)
Again, sorry this is mostly just a "what is this" question, but if anyone could tell me pros/cons towards using the method in question versus hash values, that would be great also :)
Upvotes: 0
Views: 170
Reputation: 305
The ? part is a querystring, GET parameters are sent that way.
The more interesting part of your question is: how can I enable the back-button/history for users in a dynamic website? Check out this library: https://github.com/browserstate/History.js/
It enables you (for newer browsers) to get/set history states. Each dynamic page gets it's own address. For older browsers, there is the hash-bang fallback (#/page/page).
Upvotes: 0
Reputation: 1074909
The ?
in a URL introduces the query string, which is data provided to the server. Everything prior to the ?
specifies the resource on the server (in theory), and everything after it is additional data.
So for example:
http://example.com/foo/bar/page.php?data=one http://example.com/foo/bar/page.php?data=two
Both URLs cause the page.php
page to be retrieved by the server, and since it's a PHP page, a properly-configured server will run the PHP code within it. That PHP code can access the query string data as one big string via $_SERVER['QUERY_STRING']
, or as a series of name/value pairs (if that's what it is, it doesn't have to be) via $_GET['paramname']
. Note that that's _GET
because query string parameters are GET
parameters; POST
parameters are sent via a different mechanism (not available for just links; you need a form or similar).
Upvotes: 1
Reputation: 46657
The stuff at the end of the url is a querystring. ?
is used to denote the beginning of a querystring, they use key=value
pairs seperated by &
.
To address your question of whether this can be used for bookmarking, I believe the approach you are currently using with URL hashes (#
) is correct.
Upvotes: 0
Reputation: 943902
See the url specification, in particular the section syntax components:
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
… and the definition of query.
The query component contains non-hierarchical data that, along with
data in the path component (Section 3.3), serves to identify a
resource within the scope of the URI's scheme and naming authority
(if any). The query component is indicated by the first question
mark ("?") character and terminated by a number sign ("#") character
or by the end of the URI.
Ultimately I would like to not have the page refresh
Use the history API. This is independent of the structure of the URL (other than having to be a URL on the same origin).
Upvotes: 3
Reputation: 56717
The part after the ?
is called query string. It's used to pass parameters to a web site. Parameters are separated using the &
sign. For example, this would pass parameters to a site:
http://test.site.tld/index.php?parameter=value&another=anotherValue
This would pass the parameters "parameter" (with value "value") and the parameter "another" (with value "anotherValue") to the script index.php
.
The +
sign is sometimes used to represent a space. For example, "Hello World" could be represented as "Hello+World" or "Hello%20World".
A #
sign is used to jump directly to an anchor within the page. For example
http://test.site.tld/index.php#docs
Would jump to the anchor "docs" within the web site.
Upvotes: 1