简体   繁体   中英

Toggle Pop-up using JQuery and Hashtag based URL

I've got 3 pop-ups on my page. They function using JQuery and the following JS code:

$(document).ready(function() {
    $('#open_thanks').click(function(e) {
        e.preventDefault();
        var tPop = $('.thanks_popup');
        tPop.toggle();
    });
    $('#open_reference').click(function(e) {
        e.preventDefault();
        var rPop = $('.leave_reference_popup');
        rPop.toggle();
    });
    $('#facebook').click(function(e) {
        e.preventDefault();
        var fPop = $('.facebook_popup');
        fPop.toggle();
    });


    $('.thanks_popup').append('<div class="close"><div class="inner"><button></button></div></div>');
    $('.leave_reference_popup').append('<div class="close"><div class="inner-2"><button></button></div></div>');
    $('.facebook_popup').append('<div class="close"><div class="inner-3"><button></button></div></div>');

    $('div.inner button').click(function() {
        var tPop = $('.thanks_popup');
        tPop.toggle();
    });
    $('div.inner-2 button').click(function() {
        var rPop = $('.leave_reference_popup');
        rPop.toggle();
    });
    $('div.inner-3 button').click(function() {
        var fPop = $('.facebook_popup');
        fPop.toggle();
    });

});

My html is quite simple:

<a href="#" id="open_thanks">Thanks Popup</a>

<a href="#" id="open_reference">Open Reference</a>

<a href="#" id="facebook">Open Facebook Popup</a>

I can't figure out how to use hashtag URL navigation to have a pop-up default as open though? Basically, I want to be able to link to index.html#open_thanks and have that pop-up default as open/up.

Thanks.

On page load, parse out any hash values in the url, and then do x.

How to get #hash value in a URL in JS

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