2012-01-11 90 views
2

我有包含文章的页面。当某人从外部来源点击它们时,我怎样才能让该文章在fancybox中弹出,并将索引页面作为父页面。fancybox:打开外部子页面加载它后面的父页面

我有我的网页设置的格式如下:?pages.php ID = 123

我想打开从我的index.php用的fancybox已经在该链接打开该链接。

回答

1

你可以在pages.php上检查引用,看看它是否来自外部源,然后用参数中的某些东西(例如?external = true; articleid = 123)重定向到索引页,表明Fancybox应该弹出适当的文章。

例如,在pages.php:

$(function(){ 
    if (document.referrer.indexOf(<your url>) < 0){ 
    window.location = "index.php?external=true;article=123"; 
    } 
}); 

,然后在index.php文件:

$(function(){ 
    //Insert code here to parse query string. You can find code for this online. 
    var isExternal = getValueOfExternal(); 
    var articleId = getValueOfArticleId(); 
    if (isExternal){ 
    //open fancybox 
    $.fancybox({ 
     'href': 'pages.php?id=' + articleId 
    }); 
    } 
}); 
+0

我有点明白你在说什么。我将如何传递参数并在index.php上设置一些内容,以便自动加载它。任何示例代码? – 2012-01-11 21:51:40

+0

查看示例代码的更新答案。 – 2012-01-11 22:14:48

+0

谢谢,它工作! – 2012-01-11 23:59:06