|
|
|
| как в JavaScript получить значение параметра, переданного в GET | |
|
|
|
|
|
|
|
для: larush
(18.10.2006 в 15:26)
| | прочитать из строки URL. Слова: location.href , location.search, replace .
<script>
alert(location.search.substr(1).split('&'))
//пример:
a='?id_forum=4&id_post=152334&id_theme=26329'.substr(1).split('&')
b={}
for(i=0;i<a.length;i++){
aa=a[i].split('=');
b[aa[0]]=aa[1];
}
alert([b.id_forum,b.id_post,b.id_theme]);
</script>
|
| |
|
|
|
|
|
|
|
для: 12345
(18.10.2006 в 15:59)
| | да ну. может, все-таки, из строки URL?
ex_url=location.search.substring(1);
|
| |
|
|
|
|
|
|
|
для: elenaki
(18.10.2006 в 16:02)
| | Спасибо, а вот вчера надыбал, мне понравилось-
function getfresh(param)
{
_GET=new Object;
query_str=new String(window.location).split('?').pop();
if (query_str==window.location)
return;
if (query_str.indexOf('&')>=0)
query_str=query_str.split('&');
else
query_str=[query_str];
_GET=new Object();
elt=query_str.length;
while (--elt>-1)
{
pair=query_str[elt];
if (pair.indexOf('=')<0)
pair+='=';
pair=pair.split('=');
_GET[pair.shift()]=pair.shift();
}
return _GET[param]
}
|
вызываешь getfresh('type') и получаешь значение параметра type. | |
|
|
|