简体   繁体   中英

Open link in same page and once link is open, execute some code

I have several pop-ups on home page. I open and close them by selecting them with ID and using fadeIn() and fadeOut(). Now I want to open a specific pop-up by clicking on link from another window? For example, if from that new window I click on 'Pop Up 1', I want home page to open and then show 'Pop Up 1'.

I tried using this code below but while writing this code I realized that the script gets reloaded and thus my function of loading a pop-up does not work.

So my question is, is there some elegant solution you could recommend to show element in one page while a link that specifies which element has to be shown is in another?

$("#galleryNav a").on('click', function() {
    window.open("/pixeleyes",'_self',false);

    setTimeout(function() {
        var popToShow = $(this).attr('data-pop');
        $(".text-content-outer").hide();
        $("#" + popToShow).fadeIn();            
    }, 5000);

});

One idea might work is

When you are opening a new page using the below line then send some parameter or hash value with it.

window.open("/pixeleyes",'_self',false);

like

window.open("/pixeleyes#openpopup",'_self',false);

Then in the page ready of this page check if the hash exists open the popup otherwise do nothing. Not sure if this is what you are looking for.

$("#galleryNav a").on('click', function() {
    window.open("/pixeleyes#showpopup",'_self',false);

});

showpopup could be anything that you want to open as popup...

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