Show content with fancybox like a Javascript Alert

拈花ヽ惹草 提交于 2019-12-11 02:09:17

问题


I try to show the content from a PHP-file in a fancybox but I can't handle it.

Now it's the following situation: If a file permission problem occures a <div id="error"> is shown on the website. I'd like to have the content from <div id="error"> in fancybox. Everything I try I get the notice "The requested content cannot be loaded. Please try again later."

That means the fancybox, it the file permission error occures, should be shown when the page is loading and not like usual shown when some events like click or mouseover.

For example, if the error exists, the following content should be shown in the fancybox:

<div style="width:100px; height:100px; background:#f00;">
  <p>Failure</p>
</div>

This snippet is located in a file security_check.php. Now there are two possibilities. The 1st is to load the security_check.php directly into the fancybox or to put in the mentioned above snippet.

So: how to load file contents into the fancybox?


回答1:


Have such code to load the file contents into the DIV holding the fancybox contents:

$(function() {
    $("#MyFancyContents").load("security_check.php");
});

The fancybox link should then be something like:

<a id="MyFancyLink" href="#MyFancyContents">Show</a>

And to activate, what you probably already have:

$("#MyFancyLink").fancybox();

Edit: in order to activate the fancy box when page loads rather than just by clicking the link, have such line instead:

$("#MyFancyLink").fancybox().trigger('click');



回答2:


Have I missed something? To simulate a JS alert simply:

        $.fancybox({ title: "Registration Complete", autoCenter: true, content: "<div id='alert1' ><p>Well done, you have registered!</p></div>" });

Too easy, right?



来源:https://stackoverflow.com/questions/4642344/show-content-with-fancybox-like-a-javascript-alert

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!