简体   繁体   English

通过JS代码将带有fancybox的网站进行灯箱广告

[英]Lightbox a website with fancybox from js code

I am facing an issue with fancybox right now. 我现在正遇到fancybox的问题。 I got a website, with links to articles, which are shown in fancybox when clicked. 我有一个网站,其中包含指向文章的链接,单击这些链接将显示在fancybox中。

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. 现在,当直接访问文章时,将检测到该问题,并以Articel ID作为参数将用户重定向到索引页面。 I detect this on the index page and want to open the article in fancybox right away. 我在索引页面上检测到此问题,并希望立即在fancybox中打开该文章。

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. 此代码取自fancybox文档。 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). 运行此命令时,没有显示灯箱,但奇怪的是,当我将href替换为localhost / article.jpg时,fancybox会启动并显示一个框(包含错误,内容内容无法找到等)。

Question is now: Do I need a different syntax / some special settings to open php or html pages from code? 现在的问题是: 我是否需要其他语法/一些特殊设置才能从代码打开php或html页面?

[...] //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. 我认为问题可能在于fancybox无法弄清楚应该使用iframe。 Try adding type option, it worked for me. 尝试添加类型选项,它为我工作。

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

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

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