Search code examples
jquerypluginscycle

JQuery Cycle Plugin - Go to specific slide in other page


In this link:

http://www.contactarte.com.pe/test/page1.html

I wonder if it possible to click in this page for example SLIDE4 button and go to next page showing the slide 4 in the slider.

Thanks a lot !!


Solution

  • Sure, change your href to include a query string parameter to indicate the slide:

    <a href="page2.html?slide=0">SLIDE 1</a>
    <a href="page2.html?slide=1">SLIDE 2</a>
    

    Then change the starting slide on page2 based on the query parameter passed in:

    $('#rotating-item-wrapper').cycle({
        startingSlide: (getParameterByName('slide') || 0);
    });
    

    Using the following function to extract your query string parameters (found here):

    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
        var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
        return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
    }