how to check if fancybox exists on page already

后端 未结 5 1839
猫巷女王i
猫巷女王i 2021-02-09 01:46

I am trying to check if a fancybox has been loaded already. If so then I run an ajax script to put content inside.

If not I open a fancybox iframe and it fetches content

5条回答
  •  不思量自难忘°
    2021-02-09 02:40

    In my case for ending up here in this thread, I had a script checking if user input had been detected through mouse movement or keyboard activity. However the parent page were not detecting activity when being inside a fancybox iframe.

    To adjust and compensate for this fact, I let the script running in the background know if there is an open iframe in the DOM (as I am not using iframes besides with fancybox) by using the following code:

    if ($('body iframe').length > 0)
    {
        console.log('Fancybox Open');
    }
    else
    {
        console.log('Fancybox NOT Open');
    }
    

    You could also choose to have your iframe content have a specific ID or Class that you measure, however take in mind that when the HTML element is dynamically instigated you have to target an existing parent selector first which were present at DOM to be able to find your newly created element.

提交回复
热议问题