문제

Okay one page page i have a list of links with ID's

<a id="link1">Link</a>
<a id="link2">Link</a>
<a id="link3">Link</a>
<a id="link4">Link</a>
<a id="link5">Link</a>

When i click on link 2 I want to load a second page but show link 2, the second page is a simple slider so basic layout

<ul>
   <li class="slide1">slide 1</li>
   <li class="slide2">slide 2</li>
   <li class="slide3">slide 3</li>
   <li class="slide4">slide 4</li>
   <li class="slide5">slide 4</li>
</ul>

So with jQuery i can grab link and do onclick function

$("#link3").click(function() {
document.location.href='slidepage.php';
$('.slide3').trigger('click');

});

Obv the .trigger has no effect as the page is reloading, i need to be able to say came from id=link3 so want to triger slide 3

Hope that makes sense and thanks,

도움이 되었습니까?

해결책

URL params would do this job:

Link example:

 <a id="link1" href="yourpage?id=link1">Link</a>

On the page that loads, running this script will alert the id of the slide:

$(document).ready(function(){
  urlParam = document.URL.substr(document.URL.lastIndexOf('=') + 1);
  alert(urlParam);
});

You'd need to adjust this code if you had other URL parameters going on as well, but the concept is there and it works in this basic form.

Once you have that data on the page, you can do whatever you need with it, such as show the correct slide.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top