I added this link https://website.test/about/contact-us/?modal=example
in wp backend menu editor and checked the link after I input this code that’s supposed to open the bootstrap model once the link was entered in the browser. However it didn’t work.
Here’s my javascript code that I added within <script>
at bottom under </footer>
tag.
<script type="text/javascript">
(function($) {
$(document).ready(function() {
if(window.location.href.indexOf('/?modal=example') != -1) {
$('#exampleModal').modal('show');
}
});
})(jQuery);
</script>
Every time I try to refresh or type the url in another page, it won’t load/open the modal. What’s wrong with my code?
2
Answers
Actually, the url I was looking for turned out to be like this
You could try using URLSearchParams() to check for the query param.