Topic: I need to access a carousel slide from outside the page - via the url

Mark Corrigan free asked 5 years ago


Hi Please can you help me.
I am desperate!

I went through your awesome instruction page on the carousel: https://mdbootstrap.com/docs/jquery/javascript/carousel/

Unfortunately, it does not deal with how one can access a slide in the carousel via the url.

I have tried for days to figure out how to do this but am getting nowhere.

An example of something I have tried but no examples show one how to use the url to get to a slide. Please can you help me. ===> You can use a query string like... www.example.com?slide=2

$(document).ready(function(){

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, " "));
}

$('#myCarousel').carousel(getParameterByName('slide'));

});


Mikołaj Smoleński staff answered 5 years ago


Hello Mark,

I suggest to read the index of item from url, then map carousel items and add active state to the proper item. There's the first time we have such issue and we don't have ready solution for it.

Best regards



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.7.4
  • Device: Web browsing technology
  • Browser: Google Chrome
  • OS: Windows
  • Provided sample code: No
  • Provided link: Yes
Tags