Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   document.location (https://javascript.ru/forum/misc/16401-document-location.html)

Questioner 06.04.2011 16:05

document.location
 
имеется страница: file:///D:/George/Programmirovanie/HTML/Test-value.htm?t=rthwrtwh
Как получить доступ к t?

walik 06.04.2011 16:22

Ну можно так сделать:
function getParams() {
    var tmp = new Array();      // два вспомагательных
    var tmp2 = new Array();     // массива
    var param = new Array();
 
    var get = location.search;  // строка GET запроса
    if(get != '') {
        tmp = (get.substr(1)).split('&');   // разделяем переменные
        for(var i=0; i < tmp.length; i++) {
            tmp2 = tmp[i].split('=');       // массив param будет содержать
            param[tmp2[0]] = tmp2[1];       // пары ключ(имя переменной)->значение
        }
    } else return false;
    return param;
}
 
var param = getParams();
alert(param['t']);

Serg_pnz 06.04.2011 16:26

И мои 5 копеек:

http://intuit.ru:80/r/dir/page?search#mark 

window.location.href = [url]http://intuit.ru:80/r/dir/page?search#mark[/url]
window.location.protocol = http;
window.location.hostname = intuit.ru;
window.location.host = intuit.ru:80;
window.location.port = 80
window.location.pathname = /r/dir/;
window.location.search = search;
window.location.hash = mark;

Questioner 06.04.2011 16:38

Спасибо!

Aetae 06.04.2011 18:53

Цитата:

Сообщение от Serg_pnz (Сообщение 99575)
И мои 5 копеек:

http://intuit.ru:80/r/dir/page?search#mark 
window.location.href = [url]http://intuit.ru:80/r/dir/page?search#mark[/url]
window.location.protocol = http;
window.location.hostname = intuit.ru;
window.location.host = intuit.ru:80;
window.location.port = 80
window.location.pathname = /r/dir/;
window.location.search = search;
window.location.hash = mark;

window.location.protocol = http: ,
window.location.pathname = /r/dir/page ,
window.location.search = ?search ,
window.location.hash = #mark


Часовой пояс GMT +3, время: 01:42.