fancyapps / fancybox

jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.
http://fancyapps.com/
7.29k stars 1.79k forks source link

Fancybox modal popup #2622

Closed stathimexas closed 2 years ago

stathimexas commented 2 years ago

How do I implement this popup for fancybox4 on PHP?

echo '<script>$.fancybox({ title: "some title", autoCenter: true, content: "<div ><p>some message</p></div>" });</script>';

Thank you.

fancyapps commented 2 years ago

Hi, Replace

$.fancybox({ title: "some title", autoCenter: true, content: "<div ><p>some message</p></div>" });

with

Fancybox.show([{type: "html", src: "<div ><p>some message</p></div>", caption: "some title"}]);
stathimexas commented 2 years ago

Hi. I tried this solution but it does not create the popup, as if it is ignored. I am using Fancybox4, by the way. Is there anything else I have to do to trigger it? Does it need to go to the section? Please help me. Thank you.

fancyapps commented 2 years ago

Look, the snipped I gave you previously works perfectly fine, the rest is up to you - you have to decide when and how to use it in your own code. If you are using PHP, then you have to have some basic knowledge of programming and debugging your code. Do you know what HTML entities are and what https://www.php.net/manual/en/function.htmlspecialchars.php and https://www.php.net/manual/en/function.htmlentities.php are used for?

stathimexas commented 2 years ago

Ok Jānis. I will work on it more. Thank you. I have some knowledge of both PHP and debugging. If you know how to make this snippet work for me though, I would appreciate it. I have spent hours trying to implement it.

fancyapps commented 2 years ago

There is nothing special about it, if you put it between <script> tags and fancybox js file is loaded correctly, then it will run as expected. I really do not know what to add... If you could provide a link to your page, I could quickly tell where is the problem.

stathimexas commented 2 years ago

I got it to work. Thank you so much for your help. You are always very nice and helpful.

fancyapps commented 2 years ago

Well, thanks. Sorry, but you could you tell what what the cause of the issue? Could the docs be improved to avoid similar situations to others?

stathimexas commented 2 years ago

Oh man. I have already spent more than 3 Sunday hours on this. Look: It works here. But not here. I added a "Janis" section in the page-source for your convenience. The fancybox iframe link works though. Please donate a few more minutes. Thank you so much.

fancyapps commented 2 years ago

It will work after you fix these issues on your page:

Uncaught TypeError: Cannot read properties of undefined (reading 'style')
    at showDivs ((index):278)
    at (index):270
(index):468 Uncaught ReferenceError: janis is not defined
    at (index):468
(index):469 Uncaught ReferenceError: Fancybox is not defined
    at (index):469

Please, learn to debug your code. You can press F12 to open developer tools (in any browser) and Console tab will reveal any issue. Any JavaScript error can prevent further execution of the JavaScript.

stathimexas commented 2 years ago

Jānis, thank you so much for your kind help. I apologize for not being thorough enough.