正如我在我的评论中提到的,您需要在每个“详细信息”页面中包含一个脚本来嗅探URL并检测页面是否在新窗口(首页)中打开,如果是这样重定向到主页面修改后的URL(例如使用hash
),这将允许从主页面打开fancybox中的“详细信息”页面。
所以,你可以在每一个“细节”页面包括这个脚本:
<script type="text/javascript">
var isWindow = self == top; // returns true if opened in a new window, otherwise it migh be inside an iframe
if(isWindow){
// alert("this page was opened in a new browser window");
// then redirect to main page and add hash "detailedXX"
window.location = "{URL}/mainpage.html#detailed01"
}
</script>
变化detailed01
不同的值每一个“细节”页面。
然后在主要页面,你可以有一个像
<a id="detailed01" class="fancybox" href="detailed01.html">Open project detail page 01 in fancybox</a>
<a id="detailed02" class="fancybox" href="detailed02.html">Open project detail page 02 in fancybox</a>
注意,我包括一个ID
到每个锚相匹配的hash
,我们将重新导向到主使用环节每一个细节页页。
那么你的fancybox脚本可以是这样的:
<script type="text/javascript">
var thisHash = window.location.hash;
$(document).ready(function() {
if(window.location.hash) {
// get the URL without hash so we can restore it if needed
var thisWindowLocation = window.location;
var thisWindowLocationSplit = String(thisWindowLocation).split("#")[0];
$(thisHash).fancybox({
width: 800,
height: 320,
fitToView: false,
autoSize : false,
type: 'iframe',
afterClose : function(){
// returns URL to main page with no hash
window.location = thisWindowLocationSplit
}
}).trigger('click');
}
// fancybox for normal main page operation
$(".fancybox").fancybox({
width: 800,
height: 320,
fitToView: false,
autoSize : false,
type: 'iframe'
});
}); // ready
</script>
我设置DEMO here
这个演示打开两个 “详细信息” 页面:
http://www.picssel.com/playground/jquery/detailed01.html 和 http://www.picssel.com/playground/jquery/detailed02.html
如果您尝试直接打开它们,则意志重定向t输出给calling page和的fancybox开放
来源
2012-09-03 21:38:51
JFK
从我的头顶开始,您似乎需要在每个详细信息页面中包含用于嗅探URL的脚本,并且如果在首页打开,则使用修改后的URL将其重定向到主页面....然后在主页面中,再次嗅探修改后的URL并触发在fancybox中打开适当的页面(当然,这一切都取决于结构或URL,但是您没有提供太多细节) – JFK