简体   繁体   中英

Cannot open popup from link

Hi guys i have a little problem with calling popup by id from link. It`s working on click but cannot call from url something like exaple.com/#id

 (function($) { $(document).ready(function() { //$('a.ajax-post').off('click').on('click', function(e) { $("a.ajax-post").on("click", function(e) { // show popup $(".popup.supernova").addClass("is-show"); e.preventDefault(); //Prevent Default Behaviour var post_id = $(this).attr("id"); //Get Post ID // Ajax Call $.ajax({ cache: false, timeout: 8000, url: "/wp-admin/admin-ajax.php", type: "POST", data: { action: "theme_post_example", id: post_id }, beforeSend: function() { $("#ajax-response").html("Loading"); }, success: function(data, textStatus, jqXHR) { var $ajax_response = $(data); $("#ajax-response").html($ajax_response); setTimeout(() => { $("#ajax-response").addClass("show-content"); }, 100); /* $(".popup.supernova").append(script); */ }, error: function(jqXHR, textStatus, errorThrown) { console.log( "The following error occured: " + textStatus, errorThrown ); }, complete: function(jqXHR, textStatus) {}, }); }); }); })(jQuery);
 <a href="#" id="8" class="catalog__item popup-8 ajax-post"> <span class="catalog__title">Title</span> <img src="image.jpg" alt="" id="img_8"> </a>

Can anyone tell me how to do it? and why its not working. im new in js. Thanks in advance

As per your problem, You want to open pop up when URL containers #id like this exaple.com/#id

You check if URL contains #id, then click anchor tag Programmatically

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM