コメントで述べたように、各「詳細」ページに、URL をスニッフィングし、そのページが新しいウィンドウ (トップ ページ) で開かれたかどうかを検出するスクリプトを含める必要があります。メインページからfancyboxの「詳細」ページを開くことができるURL(hash
たとえばを使用)。
したがって、各「詳細」ページに次のスクリプトを含めることができます。
<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
一致する to each アンカーが含まれていることに注意してください。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を設置しました
このデモでは、2 つの「詳細」ページが開きます。
http://www.picssel.com/playground/jquery/detailed01.html
および
http://www.picssel.com/playground/jquery/detailed02.html
それらを直接開こうとすると、呼び出し元のページにリダイレクトされ、fancybox で開きます