Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Передача значения (https://javascript.ru/forum/misc/33358-peredacha-znacheniya.html)

Aftal1ck 20.11.2012 15:23

Передача значения
 
Собственно есть код на первой странице:
function transmit() {
	        var imgSrc = table.getElementsByClassName('active_thumb')[1].getElementsByTagName('img')[2].getAttribute('src');
	        window.name = input.value+'*'+imgSrc;
	        window.location ='http://parapapa.ru/index1.html';
	            }

И код на второй:
var arr = window.name.split('*');
	    document.getElementById('id_buy_item').value = arr[0];
	    document.getElementById('preview').getElementsByTagName('img')[1].setAttribute('src', arr[2]);
	    window.name='';

Смысл в том, что мне с одной страницы на другую требуется передать текст и изображение, но в конечном счете получаю undefened.
Поможите :)

Hoshinokoe 20.11.2012 16:49

Aftal1ck,

Как только ты переходишь по ссылке, объект window создается заново.

Если хочешь передать параметры между страницами, то можно через query string.

'http://parapapa.ru/index1.html?param1=value1&param2=value2';

Aftal1ck 21.11.2012 10:19

Это уже другой лес, сделал своим способом:
На первой странице:
<script type="text/javascript">
блаблабла....
			function transmit() {
	            var imgSrc = table.getElementsByClassName('active_thumb')[0].getElementsByTagName('img')[0].getAttribute('src');
	            window.name = imgSrc;
	            window.location ='http://parapapa.ru/forest/message.html';
	        }


На второй странице:
<script type="text/javascript">
	var arr = window.name;
	    document.getElementById('id_buy_item').value = arr;
	    document.getElementById('preview').getElementsByTagName('img')[0].setAttribute('src', 'http://parapapa.ru/images/xxl/'+arr);
	    window.name='';
</script>


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