Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   url ..... зависимость блоков (https://javascript.ru/forum/jquery/25462-url-zavisimost-blokov.html)

Beriagts 06.02.2012 12:01

url ..... зависимость блоков
 
Есть index.html
<div class="main">
    <div class="1"></div>
    <div class="2"></div>
</div>

Блоки 1/2 скрытые, как сделать что бы при переходе localhost/1.html
открывался index.html + блоку class="1" передавалась функция на открытия?

T-sh 08.02.2012 07:22

в .htaccess сделать перенаправление /1.html и /2.html на index.html#1 и index.html#2 соответственно.

заменить class на id :) так удобнее.

дальше скрипт (самый простой для опнимания, но не самый опитмальный — чтоб разобраться в самый раз будет):
var a = location.hash;

if (a === "#1"){  
      var x = document.getElementById('1');
      x.style.display = 'block';
}
if (a === "#2"){ 
      var x = document.getElementById('2');
      x.style.display = 'block';
}


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