location.pathname
pathname
sarà solo restituire il percorso. Se si desidera querystring
e facoltativamente hash
, sarà necessario combinare anche le proprietà search
e hash
. Considerate questo url:
http://www.example.com/path/to/glory?key=value&world=cup#part/of/page
location.pathname => "/path/to/glory"
location.search => "?key=value&world=cup"
location.hash => "#part/of/page"
Se si desidera che l'intera cosa,
/path/to/glory?key=value&world=cup#part/of/page
poi basta concatenare tutti questi:
location.pathname + location.search + location.hash
Sempre voluto utilizzare with
da qualche parte. Questo appare come l'occasione perfetta :)
with(location) {
pathname + search + hash;
}
Cosa potrebbe avere a che fare con jQuery? –
Anurag: mentre stai modificando potresti anche liberarti della chiamata 'toString' ridondante su' location.host'. –
yikes @no, ho sovrascritto mentre stavi cambiando? – Anurag