简体   繁体   中英

Lightbox a website with fancybox from js code

I am facing an issue with fancybox right now. I got a website, with links to articles, which are shown in fancybox when clicked.

Now when an article is accessed directly, this is detected and the user get redirected to the index page, with the articel id as parameter. I detect this on the index page and want to open the article in fancybox right away.

This is the code I use:

[...] //finding out if parameter is passed and storing it in id
$.fancybox.open([
{
  href:'localhost/article.php?p='+id,
  title: 'test title'
}],
{
  padding :0
});
[...]

This code is taken from the fancybox doc. When running this, no lightbox is shown, but the strange thing is, as soon as I replace the href with localhost/article.jpg fancybox fires and shows a box (containing error, that the content content could not be fount etc).

Question is now: Do I need a different syntax / some special settings to open php or html pages from code?

[...] //finding out if parameter is passed and storing it in id
$.fancybox.open([
{
  href:'localhost/article.php?p='+id,
  title: 'test title'
}],
{
  padding :0
});
[...]

Try separating your parameters.


I think that the problem might be the fact that fancybox can't figure out that it should use iframe. Try adding type option, it worked for me.

$.fancybox.open([{
    href: 'localhost/article.php?p='+id,
    title: 'test title'
}], {
    type: 'iframe',
    padding: 0
});

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