简体   繁体   English

在同一页面中打开链接,打开链接后,执行一些代码

[英]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(). 我通过使用ID选择它们并使用fadeIn()和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'. 例如,如果在新窗口中单击“弹出窗口1”,我希望打开主页,然后显示“弹出窗口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... showpopup可以是您要作为弹出窗口打开的任何内容...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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