Trying to follow this 6-year-old guide, but my JavaScript isn't triggering when the URL contains #slide_ - have things changed?
Linking to a specific Bootstrap carousel slide from another page
My code on page 2:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<!-- Core theme CSS (includes Bootstrap)-->
<link href="css/styles.css?v20221223=1" rel="stylesheet" />
</head>
<body>
<!-- Carousel Wrapper-->
<div id="myCarousel" class="carousel carousel-dark slide" data-bs-interval="false" data-ride="carousel" data-pause="hover">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://www.w3schools.com/bootstrap/chicago.jpg" alt="..." class="d-block img-fluid">
</div>
<div class="carousel-item">
<img src="https://www.w3schools.com/bootstrap/la.jpg" alt="..." class="d-block img-fluid">
</div>
<div class="carousel-item">
<img src="https://www.w3schools.com/bootstrap/ny.jpg" alt="..." class="d-block img-fluid">
</div>
</div>
</div>
</div>
<!-- END Carousel Wrapper-->
<!-- Bootstrap core JS - versionas as of Dec 2022-->
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4c6cbcbd0d7d0d6c5d4e4918a978a9489c5c8d4cc">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>
<!-- JS for loading a particular slide from another page -->
<script>
function qs(key) {
key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&");
var match = location.search.match(new RegExp("[?&]" + key + "=([^&]+)(&|$)"));
var slide = match && decodeURIComponent(match[1].replace(/\+/g, " "));
if (Math.floor(slide) == slide && $.isNumeric(slide))
return parseInt(slide);
else
return 0;
}
//why is this not working???
$('#myCarousel').carousel(qs('slide'));
</script>
</body>
</html>
And the link on page 1
<a href="page1.html#slide=2">slide 2</a>
Feeling stuck...